正在加载图片...
说明: fseek函数一般用于二进制文件 例如:在磁盘文件上存有10个学生的数据。要求将第1、3、5、7、9个学生的数据 输入计算机,并在屏幕上显示出来 #include <stdio. h> truct student type char name [10] Int num int age char sex stud[10] main() 1nt 1 FILE *fp if((fp= fopen(“stud.dat”,"rb”)==NULL) printf(“ cannot open file\n”) exit(0): for(i=0;i<10;i+=2) I fseek(fp, i*sizeof (struct student_ type), O) fread(&stud], sizeof(struct student type), 1, fp) printf ("%s %d %d %c\n", stud[i] name, stud[i]. num, stud[i]. age, stud[] fclose(fp) ftell函数说明:fseek 函数一般用于二进制文件。 例如:在磁盘文件上存有 10 个学生的数据。要求将第 1、3、5、7、9 个学生的数据 输入计算机,并在屏幕上显示出来。 #include <stdio.h> struct student_type { char name[10]; int num; int age; char sex; } stud[10]; main( ) { int i; FILE *fp; if((fp=fopen(“stud.dat”,”rb”)= =NULL) { printf(“cannot open file\n”); exit(0);} for(i=0;i<10; i+=2) { fseek(fp, i*sizeof(struct student_type),0); fread(&stud[i],sizeof(struct student_type),1,fp); printf(“%s %d %d %c\n”,stud[i].name, stud[i].num, stud[i].age, stud[i], sex); } fclose(fp); } 3. ftell 函数
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有