摘要: 1 //-------------------------------------------1 2 #include<stdio.h> 3 #include<stdlib.h> 4 void main() 5 { 6 FILE *fp; 7 int x; 8 if((fp=fopen("f1.txt","w+"))==NULL)//打开(创建)文件为写入数据做准备 9 { 10 printf("Can't open this file!\n"); 11 exit(1); 12 } 13 pri... 阅读全文
posted @ 2013-06-12 18:03 herizai 阅读(251) 评论(0) 推荐(0) 编辑
摘要: fseek函数是用来设定文件的当前读写位置:函数原型:int fseek(FILE *fp,long offset,int origin);函数功能:把fp的文件读写位置指针移到指定的位置.fseek(fp,20,SEEK_SET);//意思是把fp文件读写位置指针从文件开始后移20个字节.ftell函数是用来获取文件的当前读写位置;函数原型: long ftell(FILE *fp)函数功能:得到流式文件的当前读写位置,其返回值是当前读写位置偏离文件头部的字节数.ban=ftell(fp);//是获取fp指定的文件的当前读写位置,并将其值传给变量ban.fseek函数与ftell函数综合应用 阅读全文
posted @ 2013-06-12 17:12 herizai 阅读(427) 评论(0) 推荐(0) 编辑
摘要: 发现fprintf(fp,"%6d",,x);与printf("%6d",x);1.函数功能 用来读写一个数据块。2.一般调用形式 fread(buffer,size,count,fp); fwrite(buffer,size,count,fp);3.说明 (1)buffer:是一个指针,对fread来说,它是读入数据的存放地址。对fwrite来说,是要输出数据的地址。 (2)size:要读写的字节数; (3)count:要进行读写多少个size字节的数据项; (4)fp:文件型指针。注意:1 完成次写操(fwrite())作后必须关闭流(fclose( 阅读全文
posted @ 2013-06-12 16:32 herizai 阅读(183) 评论(0) 推荐(0) 编辑
摘要: fopen函数用来打开一个文件,其调用的一般形式为:文件指针名=fopen(文件名,使用文件方式);其中,“文件指针名”必须是被说明为FILE 类型的指针变量;“文件名”是被打开文件的文件名;“使用文件方式”是指文件的类型和操作要求。“文件名”是字符串常量或字符串数组。例如:FILE *fp;fp=("file a","r");其意义是在当前目录下打开文件file a,只允许进行“读”操作,并使fp指向该文件。又如:FILE *fphzkfphzk=("c:\\hzk16","rb")其意义是打开C驱动器磁盘的根目 阅读全文
posted @ 2013-06-12 15:25 herizai 阅读(451) 评论(0) 推荐(0) 编辑
摘要: 1 //----------------------------1 2 #include<stdio.h> 3 #define N 5 4 struct student 5 { 6 int num; 7 char name[10]; 8 float score; 9 }; 10 11 void main() 12 { 13 int i; 14 struct student stu[N],*p; 15 p=stu; 16 printf("input information:\n"); 17 printf("学... 阅读全文
posted @ 2013-06-12 01:59 herizai 阅读(239) 评论(0) 推荐(0) 编辑