我发现了类似的问题,但我认为它们不适用于我的具体问题,所以如果它们适用,我很抱歉!
我作为一年级 CS 学生正在学习 C,并尝试用 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++;
}
你忘了声明AskForStringAndWait
功能。
在现代 C(过去的 C99)中,这将是一个错误,因为 C99 不允许调用未声明的函数。
在 C89/90 中这不是一个错误。当调用未声明的函数时,假定它返回一个int
价值。所以,你的
char* answer1 = AskForStringAndWait("Player 1: What is the capital of India?");
被解释为尝试初始化char *
指针与一个int
价值。因此发出警告。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)