The compiler error can be fixed by changing the
i < first_name;
on line 13 to
first_name[i] != '\0';
.
(You're getting the error because you're trying to compare the value of your
int i
variable with your
char first_name[100]
string.)
Two other things:
1) Don't use magic numbers like the 65, 90, 97, and 122 you have there.
You can actually just use the characters themselves:
if ( (first_name[i] >= 'A' && first_name[i] <= 'Z') || /* ... */ )
2) Your program will print "Valid name." for each valid character in the name and "Invalid name." for each invalid character.
So if I entered "Ju#ly", the program output would be
Valid name.
Valid name.
Invalid name.
Valid name.
Valid name. |
.
To fix that, consider making a
bool
variable (initially set to
true
) representing whether or not the name is valid, and if you find an invalid character, set it to
false
.
Then, after the
for
loop, print "Valid name." or "Invalid name." based on the value of that variable.