c - 错误 : no previous prototype for 'check'

标签 c compiler-errors

在我的程序中,我有一个名为hiker.c 的文件。该文件的适当内容如下:

char** answer(char c)
{

// Initial scanf and check
    printf("Please input the character which you want to build your diamond with");
    if (check(c) == true) {
        printf("\n");
    } else {
        printf("Not a valid character");
        return NULL; 
    }


 ....

我在 hiker.c 中有一个 #include "check.h" 作为 header 。 check.h的内容如下:

// Check Function for the input characters
bool check(char c)
{

int ascii = (int)c;
if (ascii < 122 && ascii > 97) {
    return false; 
            printf("Lowercase letters not allowed.");
} else if (ascii < 65 && ascii > 90) {
    return false; 
} else {
    return true; 
}

}

现在我得到错误的地方:

check.h:5:6: error: no previous prototype for 'check' [-Werror=missing-prototypes] bool check(char c)

我不明白这是什么原因。

最佳答案

这里有一个可能的 check.c 文件

#include <stdio.h>
#include "check.h"

// Check Function for the input characters
bool check(char c)
{
    int ascii = (int)c;

    if (ascii < 122 && ascii > 97)
    {
        return false; 
                printf("Lowercase letters not allowed.");
    }

    else if (ascii < 65 && ascii > 90)
    {
        return false; 
    }

    else
    {
        return true; 
    }

} // end function: check.c

这里是hiker.c文件

#include <stdio.h>
#include "check.h"


char** answer(char c)
{

// Initial scanf and check
    printf("Please input the character which you want to build your diamond with");
    if (check(c) == true) {
        printf("\n");
    } else {
        printf("Not a valid character");
        return NULL; 
    }


 ....

这里是check.h文件

#ifndef CHECK_H
#define CHECK_H

#include <stdbool.h>

bool check(char c);

#endif // CHECK_H

关于c - 错误 : no previous prototype for 'check' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32900226/

相关文章:

c - 在链表 C 中使用 free() 和内存分配

reactjs - ReactJS-Webpack编译错误: Module build failed

java - int 不能解引用编译错误

c++ - VS2013 : fatal error C1001: An internal error has occurred in the compiler

javascript - meteor 应用: Error invoking Method 'saveProject' : Internal server error [500]

c - 通过内核函数获取linux文件系统信息

c - 缩放开罗图像表面

c - __float128 不丢失信息所需的 printf 精度是多少?

c - 为什么 libonion 的 websockets.c 示例给出错误 "Cant calculate SHA1 if gnutls is not compiled in!"

spring - 无法创建内部bean'org.szymon.email.classes.MyMapperClass