隐含的函数声明

时间:2014-02-08 01:43:16

标签: c linux

我从isdigit和isalpha函数

中收到此错误
 warning: implicit declaration of function ‘isdigit’ [-Wimplicit-function-declaration]
   numberCheck = isdigit(englishWords[i]);
  warning: implicit declaration of function ‘isalpha’ [-Wimplicit-function-declaration]
   letterCheck = isalpha(englishWords[i]);

我的代码是:

char * inputEnglish()
{
    char englishWords[MAX_LENGTH];
    char required[MAX_LENGTH] = {"message="};
    char * messageToBeSent;
    int i;
    int numberCheck;
    int letterCheck;
    i = 0;

    printf("Please enter the word you'd like to translate\n");
    fgets(englishWords, MAX_LENGTH, stdin);
    for(i = 0; i < (strlen(englishWords) + 1); i++)
    {
            numberCheck = isdigit(englishWords[i]);
            letterCheck = isalpha(englishWords[i]);
            if((numberCheck != 0)  || (letterCheck != 0))
            {
                    printf("Please enter valid Input");
            }
    } 
    strcat(required, englishWords);
    messageToBeSent = malloc(sizeof(char)*(strlen(required)+1));
    strcpy(messageToBeSent, required);

    return (messageToBeSent);
}

我如何摆脱这些警告?

1 个答案:

答案 0 :(得分:4)

您正在使用编译器未被告知的函数,因此它会做出假设,特别是有关返回类型的假设。正如@ShafikYaghmour在评论中所说,正确的包含文件将为编译器提供必要的信息,即使(在这种情况下)你的代码可能会有效。