C 文件读写整理
来源:互联网 发布:品牌营销找优爵网络 编辑:程序博客网 时间:2024/04/30 15:27
feof
Checks whether the end-of-File indicator associated with stream is set, returning a value different from zero if it is.
1 #include<stdio.h> 2 #include<string.h> 3 int main() 4 { 5 FILE *fp; 6 char str[60]; 7 float f; 8 int c, n=0; 9 10 fp = fopen("file.txt", "w+"); 11 fprintf(fp, "%f %s", 3.1416, "PI"); 12 rewind(fp); 13 //fscanf(fp, "%f %s", &f, str); 14 fscanf(fp, "%f", &f); 15 fscanf(fp, "%s", str); 16 /* fgets */ 17 /* 18 fp = fopen("file.txt", "r"); 19 if(fp == NULL) { 20 perror("Error opening file"); 21 return (-1); 22 } 23 24 while( fgets(str, 60, fp) != NULL) { 25 str[strlen(str)-1]='\0'; 26 puts(str); 27 } 28 */ 29 fclose(fp); 30 printf("%f and %s \n", f, str); 31 32 fp=fopen("file.txt", "r"); 33 if(fp == NULL) 34 perror("Error opening file"); 35 else 36 while((c = fgetc(fp)) != EOF) 37 if(c == '0') 38 n++; 39 fclose(fp); 40 printf("n=%d\n", n); 41 return 0; 42 }
1 #makefile 2 #write at 20150519 3 #write by walter 4 5 CC=gcc 6 CFLAGS=-g -Wall 7 TARGETS=iotest 8 9 all:$(TARGETS) 10 11 iotest: iotest.o 12 # $(CC) $(CFLAG) -o fgets fgets.o 13 14 .PHONY: clean 15 clean: 16 rm -rf $(TARGETS) *.o
0 0
- C 文件读写整理
- C/C++读写文件相关问题整理
- c,c++读写文件的使用整理
- Android 读写文件整理
- 文件读写整理
- 【C/C++】文件读写
- java读写文件大全[整理]
- 文件读写的操作整理
- verilog读写文件(整理)
- 整理VS_2010读写.mat文件
- python文件读写和整理
- c语言读写文件
- 文件读写(c)
- C#-读写INI文件
- [C++]文件读写操作
- C#读写INI文件
- C 读写文件
- C读写ini文件
- 显示桌面实现
- winForm状态栏StatusStrip
- Light Pre-Pass 渲染器----为多光源设计一个渲染器
- sublime搜索和替换--多文件搜索替换
- CakePHP查询数据详解
- C 文件读写整理
- HDU 1255 覆盖的面积
- ImageMagicK 图片尺寸转换
- hdu 1272 小希的迷宫
- VisionEngine游戏对象中装饰组介绍
- (三)树莓派交叉编译环境配置
- 由于单表数据已经达到2000万数据,所以想分表,现假如分1000万为一单表,例有如一两个表:
- Deferred Lighting (延迟光照) + Light Pre-Pass 实现多光源动态阴影
- Cocos2dx+lua中调用按键监听