文件的读写,不知道哪里出问题了
建立一个x.txt文件。#include<stdio.h>
main()
{
int a;
FILE * fPtr;
fPtr=fopen("x.txt", "w");
scanf("%d", &a);
while(!feof(stdin))
{
fprintf(fPtr, "%d", a);
scanf("%d", &a);
}
fclose(fPtr);
system("pause");
}
===============================================================
读取x.txt文件。(不能输出意向的结果,不知道是哪里出错了。)
#include<stdio.h>
main()
{
int a;
FILE * fPtr;
if((fPtr=fopen("x.txt", "r"))==NULL)
printf("File could be opened\n");
else
{
fscanf(fPtr, "%d", &a);
while(!feof(fPtr))
{
printf("%\td", a);
fscanf(fPtr, "%d", &a);
}
fclose(fPtr);
}
system("pause");
}