简体   繁体   English

类型冲突和C中的先前隐式声明

[英]conflicting types AND previous implicit declaration in C

The error message 错误讯息

skeleton.c:86:6: warning: conflicting types for ‘verifyWord’ [enabled by default]
 void verifyWord(char nword) {
      ^
skeleton.c:79:3: note: previous implicit declaration of ‘verifyWord’ was here
   verifyWord(nextword);
   ^

void playgame() {
    .
    .
    . 
    strcpy(curword, get_random_word(dictptr));

    for(;;) {
        .
        .
        .
        /*function for nextword if correct*/
        verifyWord(nextword);
        /*                                           */
    } /* end for loop */
    .
    . 
    .
}

void verifyWord(char nword) {
FILE * fp;

fp = fopen ("usedWords.txt", "a+");
fprintf(fp, "%d ", nword);

fclose(fp);
}

Hi, this program is supposed to be a mini word game, i am new to C. Need some help in figuring out how can i avoid the error shown in the imgur image. 嗨,这个程序应该是一个迷你文字游戏,我是C的新手。需要一些帮助找出我如何避免imgur图像中显示的错误。

the above 2 is a playgame function and a verifyWord function 上面的2是一个playgame函数和一个verifyWord函数

Please point me in the right direction as i tried declaring above the main: 当我尝试在主要内容上方进行声明时,请向我指出正确的方向:

  • verifyWord(); verifyWord();
  • char verifyWord(void); char verifyWord(void);
  • char verifyWord(); char verifyWord();

You need to declare the function correctly with the arguments you are willing to pass in it. 您需要使用愿意传递的参数正确声明函数。

Let's say for example that verifyWord returns void and accepts char pointer as an argument. 例如, verifyWord返回void并接受char pointer作为参数。

The proper declaration would be: 正确的声明是:

void verifyWord (char *nextWord);

And you will use it like: 您将像这样使用它:

char* nextWord = NULL;

verifyWord(nextword);

Your problem is that you didn't tell your compiler how to deal with the function. 您的问题是您没有告诉编译器如何处理该函数。 You need to have explicit declaration, like the one I mentioned above, placed somewhere before the line where you call it, and it has to be within the same scope. 您需要有一个明确的声明,如我上面提到的那样,放置在调用它的行之前的某处,并且必须在同一范围内。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C 程序:function 和冲突类型的隐式声明 - C program: implicit declaration of function and conflicting types 错误:“…”的类型冲突; 注意:之前的隐式声明“…”在这里 - error: conflicting types for '…'; note: previous implicit declaration of '…' was here 以前的声明和冲突的类型 - Previous declaration and conflicting types 类型和先前的函数声明冲突? - Conflicting types and previous declaration of function? 类型冲突与不兼容的隐式声明 - conflicting types vs incompatible implicit declaration 得到错误:“错误:'call_celsius'的类型冲突”和“注意:此处先前的'call_celsius'的隐式声明在这里” - Getting errors: “error: conflicting types for ‘call_celsius’ ” and “note: previous implicit declaration of ‘call_celsius’ was here” x的冲突类型和先前的声明在这里......什么? - Conflicting types and previous declaration of x was here…what? Mingw -- 由于先前的声明而导致函数类型冲突 - Mingw -- Conflicting types for function due to previous declaration 不知道为什么我在C语言中遇到“冲突类型”错误和“隐式声明错误”。 - Don't know why I'm getting a 'conflicting types' error and a 'implicit declaration error' in C. 在C99中,“函数”的类型冲突和函数“函数”的隐式声明无效 - Conflicting types for 'function' and implicit declaration of function 'function' is invalid in C99
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM