0

So I'm trying to finish my "Caesar" code but it seems like I didn't understand how to use "isalpha", "islower" and "isupper" functions properly. The compiler yells at me with this error:

Implicit declaration of function 'isalpha' is invalid in C99

I'll post my code over here and hope any of you guys gives me a tip how to use those functions in a way that will make the code work. Here's the code:

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

int main(int argc, string argv[])
{
    while(argc < 2 || argc > 2)
    {
        return 1;
    }

    printf("What do you want me to encrypt?\n");
    string s = GetString();
    int k = atoi(argv[1]);

    for(int i = 0, n = strlen(s); i < n; i++)
    {
        if(isalpha(s[i]))
        {
            if(isupper(s[i]))
            {
                char v = s[i] - 65;
                char m = (v + k) % 26;
                char l = m + 65;
                printf("%c", l);
            }

            if(islower(s[i]))
            {
                char t = s[i] - 97;
                char y = (t + k) % 26;
                char u = y + 97;
                printf("%c", u);
            }
        }
        else
        {
            printf("%c", s[i]);
        }
    }

    printf("\n");
}

1 Answer 1

1

your handling of isalpha functions (), etc ... is correct but you must include the header file ctype.h

You must log in to answer this question.

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