正在加载图片...
例从键盘按格式输入数据存到磁盘文件中去 #include <stdio h> maino i char s[803, c[80; int a b FILE Ip if(fp=fopen( test",W)==NULL i puts(can't open file); exito fscanf(stdin, %os%d", S, &a); *read from keaboard*/ fprintf(fp, %s %d", s, a) /*write to file fclose(fp) if(fp=fopen(test", ID==NULL) i puts("cant open file ) exitO;j fscanf(fp, "%s%d,c, &b) /*read from file*/ fprintf( stdout, %oS %",c, b); print to screen*/ fclose(fp)#include <stdio.h> main() { char s[80],c[80]; int a,b; FILE *fp; if((fp=fopen("test","w"))==NULL) { puts("can't 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("can't open file"); exit(); } fscanf(fp,"%s%d",c,&b); /*read from file*/ fprintf(stdout,"%s %d",c,b); /*print to screen*/ fclose(fp); } 例 从键盘按格式输入数据存到磁盘文件中去
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有