第9章文件课件.pptVIP

  • 1
  • 0
  • 约1.34万字
  • 约 41页
  • 2019-11-26 发布于湖北
  • 举报
9.4.4 格式化读写函数fscanf()和fprintf() 2.从键盘按格式输入数据存到磁盘文件中去 #include stdio.h main() { char s[80],c[80]; int a,b; FILE *fp; if((fp=fopen(test,w))==NULL) { puts(cant open file); exit() ; } fscanf(stdin,%s%d,s,a);/*read from keaboard*/ fprintf(fp,%s %d,s,a);/*write to file*/ fclose(fp); if((fp=fopen(test,r))==NULL) { puts(cant open file); exit(); } fscanf(fp,%s%d,c,b);/*read from file*/ fprintf(stdout,%s %d,c,b);/*print to screen*/ fclose(fp); } 9.4.5 自定义其他类型数据的读写函数 例如,可以定义一个向磁盘文件写一个实数(用二进制方式)的函数putfloat: putfloat(float num,FILE *fp) { char *s; int

文档评论(0)

1亿VIP精品文档

相关文档