我发现了类似的问题,但我不认为它们适用于我的具体问题,所以如果他们这么做,我很抱歉!警告 - 初始化使得整型指针没有强制转换
我正在学习C作为第一年的CS学生,并试图在C中进行测验,但我无法获得任何地方,因为每次我尝试编译以查看它是否正常工作,我都会收到消息“警告:初始化使得整型指针没有转换。“
我已经制定了所有的语法错误(我认为),但我只是为了我的生活无法弄清楚这一点。我已经浏览了所有的演讲幻灯片,但没有一本介绍。
#include <stdio.h>
#include <scc110.h>
int player1score, player2score;
char* answer1, answer11, answer111, answer2, answer22, answer222;
int geography()
{
printf ("The first category is geography. Note: Player 1 always goes first.\n");
char* answer1 = AskForStringAndWait("Player 1: What is the capital of India?");
if (strcmp(answer1,"New Delhi")==0)
player1score++;
char* answer2 = AskForStringAndWait("Player 2: What is the capital of Iran?");
if (strcmp(answer2,"Tehran")==0)
player2score++;
char* answer11 = AskForStringAndWait("Player 1: Name a country that borders France that isn't Germany, Italy or Spain.");
if (strcmp(answer11,"Luzembourgh")==0 ||
strcmp(answer11,"Switzerland")==0 ||
strcmp(answer11,"Belgium")==0)
player1score++;
char* answer22 = AskForStringAndWait("Player 2: Name one of the main British Channel Islands.");
if (strcmp(answer22,"Guernsey")==0 ||
strcmp(answer22,"Jersey")==0)
player2score++;
}
您需要在使用它之前声明该函数。 – chris
而在你的全局声明中,只有'answer1'是'char *',其他的都是普通的'char'。 –
请注意,您的全局变量'answer1'等由局部变量映射到函数geography()中。这通常会导致混淆。在这种情况下,摆脱全局变量。 –