C语言程序设计,求高手解答,感激不尽

编写一个程序实现如下功能:有一个整数文件(二进制文件),读取其中的数值,如果为奇数加一;如果为偶数,减一,存放到新的文件中去。

C语言编译,若有解答,感激不尽。

#include<stdio.h>
#include<process.h>

void main()
{
int n;
FILE *fp,*fp1;
if((fp=fopen("data.txt","rb"))==NULL)
{
printf("can not open this file!\n");
exit(0);
}
if((fp1=fopen("data1.txt","w"))==NULL)
{
printf("can not open this file!\n");
exit(0);
}
while(fscanf(fp,"%d",&n)!=EOF)
{
fscanf(fp,"%d",&n);
if(n%2==0)
n=n-1;
else
n=n+1;
fprintf(fp1,"%5d",n);
}
fclose(fp);
fclose(fp1);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-05-31
基础题,看看书吧。要实践,才有收获
相似回答
大家正在搜