gpt4 book ai didi

c - 警告 - 初始化使指针从整数而不进行强制转换

转载 作者:行者123 更新时间:2023-12-04 12:33:04 24 4
gpt4 key购买 nike

我发现了类似的问题,但我认为它们不适用于我的具体问题,所以如果它们适用,我很抱歉!

我正在学习 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++;
}

最佳答案

您忘记声明 AskForStringAndWait 函数。

在现代 C(过去的 C99)中,这将是一个错误,因为 C99 不允许调用未声明的函数。

在 C89/90 中,这不是错误。当调用未声明的函数时,假定它返回一个 int 值。所以,你的

char* answer1 = AskForStringAndWait("Player 1: What is the capital of India?");

被解释为尝试用 char * 值初始化 int 指针。因此警告。

关于c - 警告 - 初始化使指针从整数而不进行强制转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13314049/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com