I am stuck on validating the user input for the key phrase in vigenere (there aren't a lot of questions on here about that, so I am guessing I am missing something rather obvious...).
I was trying to use !isalpha()
and after learning that I cannot pass a string into the function, I tried using a for loop to iterate through the char's in the key phrase. However, my program won't compile, giving me the error statement:
"expected expression"
(with the little green ^ pointing at the beginning of the for loop).
My suspicion is that I've got the syntax wrong, but I have not been able to find any resource on using for loops as a condition inside an if statement (maybe this just does't work?).
Looking at my code, can anyone give me a hint as to why I am seeing this error or point to toward a more elegant solution for user input validation?
Many thanks!
vigenere.c
int main (int argc, string argv[])
{
// check user input
if (argc !=2)
{
printf("please follow command ./vigenere with a key word (letters only)\n");
return 1;
}
else if (
for (int h = 0, n = strlen(argv[1]); h < n; h++)
{
if ( !isalpha(argv[1][h]) )
}
)
{
printf("please follow command ./vigenere with a key word (letters only)\n");
return 1;
}