windos vc++6.0通过;
功能:格式化的向文件中读取,写入数据
注意:输入的时候字符要紧挨着数字输入,不然会读取到空格。
#include<stdio.h>
main()
{
int a,a1;
float b,b1;
char c,c1;
FILE *fp;
if((fp=fopen("ttt.txt","w+"))==NULL)
{
printf("Cannot open file!\n");
exit(1);
}
printf("请输入a,b,c:");
scanf("%d",&a);
scanf("%f",&b);
scanf("%c",&c);
printf("%d,%f,%c",a,b,c);
fprintf(fp,"%d,%f,%c",a,b,c);
fclose(fp);
fp=fopen("ttt.txt","r");
fscanf(fp,"%d,%f,%c",&a1,&b1,&c1);
printf("%d,%f,%c",a,b,c);
printf("%d,%f,%c",a1,b1,c1);
}