Problem with string input check.

Hello, I have to write a function that will check if the string is legas or not.
Legal means that only letters is allowed and the ','. So abc,AV is legal but abc,4av is not. The problem is when I enter something with the ' ' , so when I enter abc, ABC I get legal.
what am I doing wrong?

Here is the code
1
2
3
4
5
6
7
8
9
10
11
bool checkIfNormal(char str1[])
{
 int strSize = strlen(str1);
 int i;
 for(i = 0; i < strSize; i++ )
 {
  if((!((str1[i]>='a' && str1[i]<='z') || (str1[i]>='A' && str1[i]<='Z') || str1[i]==','))
   return true;
  }
 return false;
}
I think yours is a little complicated than it should be. idk if you are allowed to use the cctype header but it has exactly what you need for this problem.

http://www.cplusplus.com/reference/cctype/
Last edited on
Topic archived. No new replies allowed.