各种的函数
来源:互联网 发布:淘宝买篮球鞋的好店 编辑:程序博客网 时间:2024/05/16 08:17
1. fopen
Opens the file whose name is specified in the parameter filename and associates it with a stream that can be identified in future operations by the FILE object whose pointer is returned
FILE * fopen ( const char * filename, const char * mode );
"r"Open a file for reading. The file must exist."w"Create an empty file for writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file. "a"Append to a file. Writing operations append data at the end of the file. The file is created if it does not exist."r+"Open a file for update both reading and writing. The file must exist."w+"Create an empty file for both reading and writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file."a+"Open a file for reading and appending. All writing operations are performed at the end of the file, protecting the previous content to be overwritten. You can reposition (fseek, rewind) the internal pointer to anywhere in the file for reading, but writing operations will move it back to the end of file. The file is created if it does not exist.2. sscanf() - 从一个字符串中读进与指定格式相符的数据.
Int sscanf( const char *, const char *, ...);
参数可以是一个或多个 {%[*] [width] [{h | l | I64 | L}]type | ' ' | '/t' | '/n' | 非%符号}
集合操作
%[a-z] 表示匹配a到z中任意字符,贪婪性(尽可能多的匹配)
%[aB'] 匹配a、B、'中一员,贪婪性
%[^a] 匹配非a的任意字符,贪婪性
#include <stdio.h>
int main()
{
const char* s = "iios/12DDWDFF@122";
char buf[20];
sscanf( s, "%*[^/]/%[^@]", buf );
printf( "%s/n", buf );
return 0;
}
3. fgets和gets
fgets原型是char *fgets(char *string, int n, FILE *stream);
是c的文件操作函数
负责从文件流中读取字符串
gets则是标准输入流中获取字符串
char *fgets(
char* string,
int n,
FILE *stream
);
char *gets(
char* buffer
);
4. mkdir
创建文件夹的命令,直接用字符串形式给出路径和文件名就可以
5. strtok
extern char *strtok(char *s, char *delim);
功能:分解字符串为一组标记串。s为要分解的字符串,delim为分隔符字符串。
说明:首次调用时,s必须指向要分解的字符串,随后调用要把s设成NULL。
strtok在s中查找包含在delim中的字符并用NULL('/0')来替换,直到找遍整个字符串。
返回指向下一个标记串。当没有标记串时则返回空字符NULL。
6. clrscr
清屏
7. fwrite
#include<direct.h>
#include<fstream>
#include<string.h>
#include <stdio.h>
main()
{
FILE *fp;
char pathname[80]="D://mkdir1" ;
char name[20];
puts("input name");
gets(name);
mkdir("D://mkdir1");
strcat(pathname,"//");
strcat(pathname,name);
fp=fopen(pathname,"w");
fwrite("111",3,1,fp); //输入buffer或者数据,字节数,重复数,文件指针
fclose(fp);
return 0;
}
8. sprintf
#include<direct.h>#include<fstream>
#include<string.h>
int main()
{
FILE *fp;
char name[20],fullpath[260]={0};
puts("input name");
gets(name);
mkdir("D://mkdir1");
sprintf(fullpath,"%s%s","D://mkdir1//",name); //格式化字符输出到字符串中
fp=fopen(fullpath);
return 0;
}
- 各种的函数
- 各种函数的总结
- 线程的各种函数
- 校验各种类型的函数
- 各种读写函数的整理
- 各种构造函数的区别
- 实现各种功能的函数
- js的函数各种状态
- 各种构造函数的调用
- 各种常用的JS函数
- apue里面的各种函数
- Swift 函数的各种使用
- Matlab各种分布的函数
- php的各种比较函数
- 各种时间函数的使用
- 各种优化函数的介绍
- 各种激活函数的比较
- 各种函数
- java中io与nio的使用
- TestComplete新特性窥探 - 改进的分布式测试
- 不重复固定长度随机号的产生
- API函数详解
- 售前工程师岗位职责和基本要求
- 各种的函数
- 软件开发中的十三种文档
- ASP.NET ViewState 初探
- test~~~
- strcmp
- sql 内连接 外连接
- C# 获取句柄
- 基于mini2440的qtopia程序设计之二:如何在qtopia创建快捷方式
- 复选框文字对齐显示