【发布时间】:2010-04-25 17:42:00
【问题描述】:
我是使用数组和文件编程 c 的新手。 我只是试图运行以下代码,但我收到这样的警告:
23 44 警告:赋值使指针来自 没有强制转换的整数
53 错误:之前的预期表达式 ‘字符’
有什么帮助吗?这可能很愚蠢……但我找不到问题所在。
#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;
}
【问题讨论】:
-
它是否表示行号?那条线上是什么?
-
另外,在提交问题之前减少示例代码是有用的,通过删除无关的位;这可以很容易地简化为一个五行示例。
-
与您的问题无关,但绝不,永远使用
gets。 -
jamesdlin 你能说得更具体点吗?为什么不?我只是一个初学者,不知道很多提示和技巧。
-
您使用的是 IDE 还是程序员的编辑器?如果是这样,你能告诉我们哪一行有错误吗?