在我的程序中,我有一个名为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/