File ——fscanf&fprintf
View Code
#include<stdio.h>
#include<stdlib.h>
FILE *fp;
int main()
{
long l;
float f;
char s[89];
char c;
fp=fopen("C:\\file\\fscanf_fprintf.txt", "w+");
if(fp==NULL) printf("Can't Open The File\n");
else
{
fprintf(fp, "%s %d %f%c", "stringbutwithoutblank", 57587, 4.484, 'x');//向文件輸入內容
fseek(fp, 0L, SEEK_SET); //fseek的作用是重置fp的位置,0L表示偏移量為0,seek_set表示文件開頭
fscanf(fp, "%s%d%f%c", s, &l, &f, &c); //從文件讀出內容
printf("%s\n%d\n%f\n%c\n", s, l, f, c); //輸出讀出的內容
fclose(fp);
}
return 0;
}
fscanf 和 fprintf 的詳細用法如上面的代碼所示。
上面代碼的運行結果為:

posted on 2011-11-06 00:37 More study needed. 閱讀(246) 評論(0) 收藏 舉報

浙公網安備 33010602011771號