题目: 对文件中的每个数据加1
文件中的数据如:
1,2,3,4,5,6,7,8,9
修改以后的数据:
2,3,4,5,6,7,8,9,10
#include<stdio.h>
#include<stdlib.h>
void print(FILE *p)
{
printf("output:\n");
int num;
while(num != EOF){
num = getw(p);
printf("%d ",num);
}
}
int main()
{
void print(FILE *p);
FILE *f_pointer;
if((f_pointer = fopen("textfile","wt")) == NULL){
printf("cannot open the file!\n");
exit(0);
}
printf("please enter 10 numbers:\n");
for(int i = 0 ; i < 10 ; i ++){
int n;
scanf("%d",n);
putw(n,f_pointer);
}
printf("these numbers are successfully save in textfile!\n");
print(f_pointer);
rewind(f_pointer);
int a[10];
fread(a,sizeof(a),1,f_pointer);
for(i = 0 ; i < 10 ; i++){
a[i]+=1;
}
rewind(f_pointer);
fwrite(a,sizeof(a),1,f_pointer);
print(f_pointer);
}
运行总是出错,那位大侠帮看看啊 !急急急!