Graham
Graham

Reputation: 120

missing prototype error

I'm getting an error I don't understand and can't find a solution.

The error is as follows:

missing prototype for isANumber

the code it refers to is:

double prompt(char *promptString) {

    printf("%s", promptString);
    char *input = "";
    scanf("%s", &*input);
    printf("%s\n", &*input);

    int check = isANumber(input);


if (check) {
    return (double) *input;
} else {
    return 0.00;
}

}

int isANumber(char *check) {

    int result = 0;    /* Current isdigit() return value */
    do                           /* Check that each character of the...*/
        result = isdigit(*check++);  /* ...string is a digit and move on...*/
    while (result && *check);       /* ...until non-digit found or at EOS */
    return result;  /* Return result of last isdigit() call */

}

libraries included:

#include <stdio.h>
#include <limits.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>

Any help would be appreciated :)

Upvotes: 2

Views: 14298

Answers (3)

CapelliC
CapelliC

Reputation: 60014

declare the prototype before the use:

int isANumber(char *check);

or (simpler) swap the functions

Upvotes: 1

jn1kk
jn1kk

Reputation: 5102

You're missing the prototype for

int isANumber(char *check) {

Which should be:

int isANumber(char *);

at the top.

Upvotes: 0

Mysticial
Mysticial

Reputation: 471229

You can't forward reference like that. You need to declare or define isANumber before you can reference it:

Put this before your prompt function:

int isANumber(char *check);

Upvotes: 1

Related Questions