小程序错误!谭书上的
程序1是正确 的:
#include <stdio.h>
void main()
{
FILE *fp;
char ch, filename[10];
scanf( "%s ",filename);
if(( fp = fopen(filename, "w ")) == NULL)
{
printf( "cannot open the file!\n ");
exit(0);
}
ch = getchar();
ch = getchar();
while(ch != '# ')
{
fputc(ch,fp);
putchar(ch);
ch = getchar();
}
fclose(fp);
}
程序2:
#include <stdio.h>
main()
{
FILE *in, *out;
char ch, infile[10], outfile[10];
printf( "Enter the infile:\n ");
scanf( "%s ", infile);
printf( "Enter the outfile:\n ");
scanf( "%s ",outfile);
if((in = fopen(infile, "r ") == NULL))
{
printf( "cannot open the infile!\n ");
exit(0);
}
if((out = fopen(outfile, "w+ ") == NULL))
{
printf( "cannot open the outfile!\n ");
exit(0);
}
while(! feof(in))
fputc( fgetc(in), out);
fclose(in);
fclose(out);
}
警告 1-29.c 16: 不可移动的指针(地址常数)赋值在 main 函数中
警告 1-29.c 16: 可能是不正确的赋值在 main 函数中
[解决办法]
if((in = fopen(infile, "r ") == NULL))
==>
if( (in = fopen(infile, "r ") ) == NULL )
同理下一个
[解决办法]
不太相信小谭会犯这样的错误,可能是排版的问题.
[解决办法]
我运行了一下不能打开 infile 这是怎么会是 "r "只能打开一个已经存在的文本文件吗?
[解决办法]
if((in = fopen(infile, "r ") == NULL))
括号有问题
[解决办法]
在TURBO C中,没有任何总是