Well, one way to determine whether a string
contains any non-alphabetical char
s is to iterate over the char
s of this string
character by character, checking whether this character is an alphabetical character using a function like isalph()
.
The function isalpha()
receives a char
as an argument (not a whole string
like argv[1]
), returns true
in case it's an alphabetical char
and false
otherwise.
The pseudocode for this might be something like
for (int i = 0 to i = the length of the string - 1, increment i by 1)
{
if the current character in the string in an not an alphabetical char
{
print an appropriate error message
return 1
}
}
Given that a string
is just an array of char
s, you can access a char
within a string
using the bracket notation. For example
string s = "hello";
printf("%c\n", s[0]); // prints the 'h'
printf("%c\n", s[2]); // prints the 'l'
printf("%c\n", s[4]); // prints the 'o'
Given that argv[]
is an array of string
s, argv[x]
accesses the x th string
in that array and argv[x][y]
accesses the y th char
in the x th string
in that array.