例:从键盘按格式输入数据存到磁盘文件中去 maino i char s[80, c[ 80 int a. b: FILE *fp; if((fp=fopen("test",W==NULL i puts("can't open file); exito; scanf(%os%d", S, &a); /*read from keyboard fprintf(fp, %s %d, s, a);/*write to file*/ fclose(fp) if((fp=fopen("test",rD==NULL) i puts("can't open file ); exit(; fscanf(fp, %os%d",C, &b); *read from file*/ printf( %os%d",, b /*print to screen fclose(fp);main() { char s[80],c[80]; int a,b; FILE *fp; if((fp=fopen("test","w"))==NULL) { puts("can't open file"); exit() ; } scanf("%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*/ printf("%s %d",c,b); /*print to screen*/ fclose(fp); } 例: 从键盘按格式输入数据存到磁盘文件中去