函数 | 说明 |
---|---|
gcvt() | 将浮点型数转换为字符串(四舍五入) |
index() | 查找字符串并返回首次出现的位置 |
rindex() | 查找字符串并返回最后一次出现的位置 |
strcasecmp() | 判断字符串是否相等(忽略大小写) |
strcpy() | 复制字符串 |
strdup() | 复制字符串 |
strncasecmp() | 比较字符串的前n个字符 |
http://www.cnblogs.com/Shirlies/p/4282182.html
1. 打开文件
int openFile1(void) { FILE *file; int ch; if((file=fopen("test.txt", "r")) == NULL) { printf("the file can't be opened! "); exit(1); } //int fgetc(FILE *stream); 将把由流指针指向的文件中的一个字符读出 while((ch=fgetc(file)) != EOF) { putchar(ch); //fputc(ch,stdout); } if(fclose(file) == 0) { printf("Succeed closed! "); } //关闭多个文件,fcloseall() //fcloseall(); return 0; } int openFile2(void) { FILE *file; char str[128]; if((file=fopen("test.txt", "r")) == NULL) { printf("the file can't be opened! "); exit(1); } while(!feof(file)) { if(fgets(str,2,file)!=NULL) printf("%s ", str); } if(fclose(file)!=0) { printf("File cannot be closed "); exit(1); } else printf("File is now closed "); }