0

Im trying to declare a new function to use in vigenere, I want to create a function that will check if an entire string is alphabetical (not just a single character in a string which is what the isalpha() function does). I'll paste my code below, but what I'm really stuck on is getting the function to return a 1 true or false after I've checked all characters in the string.: int main(int argc, string argv[]) { if (argc == 2) { bool sisalpha(string a, int i, char a[i]);

 bool sisalpha(string a, int i, int n, char a[i]) { for (i = 0, n = strlen(a); i < n; i++) if (isalpha(a[i])) { return true; } else { return false; } 

Let me know if you have any suggestions!

1 Answer 1

1

You could test for "not alpha" and return false straightaway. Then, if you finish the entire loop, you know that all the chars were alpha.

for loop over string if not alpha(char) return false <-- this ends the function // loop ended so all must be alpha return true 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.