这到底是怎么一回事,请高手帮忙?
#include<stdio.h>main()
{
FILE *fp,*fp2;char ch;
fp = fopen("1.txt","r");
fp2 = fopen("12.txt","w");
for(;(ch = getc(fp)!=EOF);)
putc(ch, fp2);
}
执行完后,我打开12。txt 发现里面全是 一个个方框的字符 why?这不是我想要的。
2010-05-02 16:53
程序代码:#include<stdio.h>
main()
{
FILE *fp,*fp2;char ch;
fp = fopen("1.txt","r");
fp2 = fopen("12.txt","w");
for(;(ch = getc(fp)!=EOF);)//应是(ch = getchar())!='0';注意优先级别。还有ch是字符类型,用返回EOF判断是个陷阱,
//他容不下EOF。你可以把ch定义为int.
putc(ch, fp2); //这里是fputc函数
}我改了一下:
程序代码:#include<stdio.h>
main()
{
FILE *fp,*fp2;
char ch;
fp2 = fopen("12.txt","w");
for(;(ch = getchar())!='0';)
fputc(ch, fp2);
}
2010-05-02 18:06
2010-05-02 18:13
2010-05-02 20:42

至于那个括号是打少了吧。

2010-05-02 21:01
程序代码:#include<stdio.h>
int main()
{
FILE *fp,*fp2;
int ch;
fp = fopen("1.txt","r");
fp2 = fopen("12.txt","w");
while((ch=fgetc(fp)) != EOF)
fputc(ch, fp2);
return 0;
}
2010-05-02 22:22
程序代码:#include<stdio.h>
int main(void)
{
char c;
while((c = getchar()) != EOF)
putchar(c);
return 0;
}存在问题吗?它看起来没问题,运行“正常”。
2010-05-02 22:42

2010-05-02 23:47
2010-05-03 08:38

2010-05-03 18:10