0

I'm having an issue with my code for pset2, Readability.

My code so far is:

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


int main(void) {

string s = get_string("Text: ");
int letters = 0;
int words = 0;
int sentences = 0;

for (int i = 0; i < strlen(s); i++)
{
    if (alnum(s[i]))
    {
        letters++;
    }
}

printf("%i letter(s)\n", letters);
}

The failure I keep getting when trying to make the file is:

eadability.c:16:9: error: implicit declaration of function 'alnum' is invalid in C99
      [-Werror,-Wimplicit-function-declaration]
    if (alnum(s[i]))
        ^
1 error generated.
<builtin>: recipe for target 'readability' failed
make: *** [readability] Error 1

When I use help50 I get:

You seem to have an error in readability.c on line 16. By "implicit declaration of function 'alnum'", clang means that it doesn't recognize alnum. Did you forget to #include the header file in which alnum is declared atop your file? Did you forget to declare a prototype for alnum atop readability.c?

I'm not totally sure I understand what it means by declaring a prototype but can someone help me understand why the #include ctype.h doesn't seem to be working?

1 Answer 1

2

Pretty sure you meant isalnum.

But shouldn't it be isalpha?

1
  • You're right. Typos will be the death of me.
    – blakewp
    Commented Jan 8, 2020 at 0:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .