SDG
SDG

Reputation: 2342

error: no previous prototype for 'check'

In my program, I have a file called hiker.c. The appropriate contents of this file are below:

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; 
    }


 ....

I have a #include "check.h" as a header in hiker.c. The contents of check.h are as below:

// 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; 
}

}

And now I get the error where it says:

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

I do not understand the cause of this.

Upvotes: 1

Views: 1596

Answers (1)

user3629249
user3629249

Reputation: 16540

here is a possible check.c file

#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

here is the hiker.c file

#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; 
    }


 ....

and here is the check.h file

#ifndef CHECK_H
#define CHECK_H

#include <stdbool.h>

bool check(char c);

#endif // CHECK_H

Upvotes: 1

Related Questions