警告-初始化会使指针从整数开始而不进行强制转换 [英] Warning - Initialization makes pointer from integer without a cast

查看:416
本文介绍了警告-初始化会使指针从整数开始而不进行强制转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I found similar questions but I don't think they applied to my specific problem, so I'm sorry if they do!

我正在学习C作为刚开始学习CS的大一学生,并尝试使用C进行测验,但是我什么也做不了,因为每次我尝试编译以查看是否正常时,我都会收到消息警告:初始化使指针从整数开始而没有强制转换。

I'm learning C as a first year CS student and trying to make a quiz in C, but I can't get anywhere because every time I try to compile to see if it's working I get the message "warning: initialization makes pointer from integer without a cast."

我已经解决了所有语法错误(我认为),但是我一生都无法解决。我看完了所有的演讲幻灯片,但都没有涵盖。

I've worked out all of the syntax errors (I think) but I just for the life of my can't figure this out. I've gone through all of my lecture slides but none of them cover this.

#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不允许调用未声明的

In modern C (past-C99) that would be an error, since C99 does not allow calling undeclared functions.

在C89 / 90中这不是错误。调用未声明的函数时,假定它返回 int 值。因此,您的

In C89/90 it is not an error. When an undeclared function is called, it is assumed that it returns an int value. So, your

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

被解释为试图初始化 char * 指针,其值为 int 。因此是警告。

is interpreted as an attempt to initialize a char * pointer with an int value. Hence the warning.

这篇关于警告-初始化会使指针从整数开始而不进行强制转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆