Problem with isalpha() and isprint()

Im trying to write a program that counts the characters in a string, i used the isalpha function in one of my functions and it worked fine but every time i try to call isalpha or isprint after that it doesnt work.
The error that pops up is:
expression c >= -1 && c <=255
Line 56

Here is my code where it works:

int countWords(char str[] , const int size)
{
int words = 0;
for(int i = 0; i < size; i++0
{
if (isalpha(str [i - 1]))
words++;
}
return words;
}

Here is where it doesnt work:

int largestWord(char str[], const int size)
{
int count = 0;
for(int i = 0; i < size; i++0
{
if (isalpha (str [i]))
count++;
}
return count;
}

Last edited on
1
2
3
4
for(int i = 0; i < size; i++0
{
if (isalpha(str [i - 1]))
//... 


string indexation starts from 0, so for i = 0, i - 1 == -1 which is out-of-bounds
Last edited on
Topic archived. No new replies allowed.