FIL*_*IaS 2 c arrays warnings file
我是编程c的新手,带有数组和文件.我只是试图运行以下代码,但我得到这样的警告:
23 44警告:赋值时将整数指针,未作铸
53错误:'char'之前的预期表达式
有帮助吗?这可能是愚蠢的...但我找不到什么是错的.
#include <stdio.h>
FILE *fp;
FILE *cw;
char filename_game[40],filename_words[40];
int main()
{
while(1)
{
/* Input filenames. */
printf("\n Enter the name of the file \n");
gets(filename_game);
printf("\n Give the name of the file2 \n");
gets(filename_words);
/* Try to open the file with the game */
fp=fopen(/* args omitted */); //line23**
if (fp!= NULL)
{
printf("\n Successful opening %s \n",filename_game);
fclose(fp);
puts("\n Enter x to exit,any other to continue! \n ");
if ( (getc(stdin))=='x')
break;
else
continue;
}
else
{
fprintf(stderr,"ERROR!%s \n",filename_game);
puts("\n Enter x to exit,any other to continue! \n");
if (getc(stdin)=='x')
break;
else
continue;
}
/* Try to open the file with the names. */ //line 44**
cw=fopen(/* args omitted */);
if ( cw!=NULL )
{
printf("\n Successful opening %s \n",filename_words);
fclose(cw);
puts("\n Enter x to exit,any other to continue \n ");
if ( (getc(stdin))=='x')
break; //line 53**
else
continue;
}
else
{
fprintf(stderr,"ERROR!%s \n",filename_words);
puts("\n Enter x to exit,any other to continue! \n");
if (getc(stdin)=='x')
break;
else
continue;
}
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
你在这里缺少括号:
if (fp=fopen("crypt.txt","r")!=NULL)
Run Code Online (Sandbox Code Playgroud)
该!=
运营商的优先级高于=
所以编译器看到这样的表达:
if ( fp = ( fopen("crypt.txt","r") != NULL ) )
Run Code Online (Sandbox Code Playgroud)
fp
得到1或0取决于是否fopen
返回NULL
.fp
是一个指针,0/1是一个整数,因此警告.
你要
if ( ( fp=fopen("crypt.txt","r") ) != NULL )
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4590 次 |
最近记录: |