Codehatter
Codehatter

Reputation: 11

Is there a missing code on the isupper function?

#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
#include <math.h>

// Prototype

string Get_text(void);
char isupper(ch);



int main(void)


{
    string text = Get_text();
    printf("%s\n", text );

}

// Prompt the user for text
string Get_text(void)
{
    string n;

    do {
        n = get_string("Text: ");
    }

    while (n >= 0);

// Letters, Words, & Sentences

  char ch = 'A';

}

I encountered an error when I ran my code. It point out to line 9 where I implemented the isupper function to check if the letters are capital. I even included an extra parenthesis on the isupper before the parenthesis on char but there's still errors. P.S I'm not yet done with the code. I'm reviewing how the isupper function works.

Upvotes: 1

Views: 113

Answers (2)

Luis Colorado
Luis Colorado

Reputation: 12698

The isupper identifier coincides with a <ctype.h> function/macro that is included in the standard library.

As there's an already introduced prototype for the isupper function (int isupper(int ch);) that doesn't match the one you have used, it is giving you an error.

Simply call it otherwise (more if you plan to use the <ctype.h> routines) and not isupper.

Upvotes: 0

Joshua
Joshua

Reputation: 43317

isupper was once a macro. Never declare it. #include <ctype.h> does the right thing.

If the offending declaration were for something other than isupper I would answer rather as follows:

char isupper(ch);

is bad syntax because it should be (type argumentname) in parenthesis. It would rather be as it appears in the man page (taking the luxury of correcting the type)

int isupper(int ch);

but as I said don't actually do this because of macro fun for the builtins in ctype.h.

Anyway, you're coding in c (from the tag) so there's no stock string type. This is not a compilable fragment; thankfully the line you're asking about occurs early enough that we can tell anyway what the problem is.

Upvotes: 1

Related Questions