标题:程序运行不了,总是出错,求解
取消只看楼主
cxt631
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-12-24
 问题点数:0 回复次数:0 
程序运行不了,总是出错,求解

题目: 对文件中的每个数据加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);
}
运行总是出错,那位大侠帮看看啊 !急急急!

搜索更多相关主题的帖子: num 求解 pointer 
2006-12-25 19:01



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-112006-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.193194 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved