#Is there a better and cleaner way to write this if statement

1 messages · Page 1 of 1 (latest)

static cypress
#

I have a function that checks if a character is an alphabet or not. It returns 1 if it is and 0 otherwise. According to the assignment, the use of the function isAlpha() from the standard library is not allowed
My question is:
Is there a better way to write this if statement

{
        if (c <= 122 && 
            c != 91 && 
            c != 92 && 
            c != 93 && 
            c != 94 && 
            c!= 95 && 
            c != 96 && 
            !(c > 122) &&
            !(c < 65))
        {
                return 1;
        }
        else
        {
                return 0;
                _putchar(c);
        }
        return 0;
}```
chrome haloBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

lavish venture
#

And if you want to include digits, then:

int _isalpha(int c) {
    return (('a' <= c && c <= 'z')
         || ('A' <= c && c <= 'Z')
         || ('0' <= c && c <= '9'));
}
frail lichen
#

this should be using bool and char tbh

lavish venture
#

They then just say:

These functions check whether c, which must have the value of an
unsigned char or EOF, ...

frail lichen
#

yeah, tbh the task is written to suggest this

#

still ugly C-isms

static cypress
#

!solved

chrome haloBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity