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]))

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
    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?


Pretty sure you meant isalnum.

But shouldn't it be isalpha?

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

You must log in to answer this question.

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