You are meant to reject any number of command-line arguments other than one (means
argc
should be2
).To test whether a given character is numeric/alphabetic, you can use the
isdigit
/isalpha
function (actually implemented as a macro, so mistakes in code might show up in weird ways), likeif (isalpha(argv[1][j]))
. Or, test a range, likeif (argv[1][j] >= '0' && argv[1][j] <= '9')
orif (argv[1][j] >= 'A' && argv[1][j] <= 'Z' || argv[1][j] >= 'a' && argv[1][j] <= 'z')
(&&
has precedence over||
like*
has over+
). If you want to negate that last expression without some!
in front of everything, have fun with De Morgan's laws (it looks worse than it is). And keep in mind that non-alphabetic does not mean numeric or the other way around. Punctuation is neither nor. So test for good or non-good, not specific bad characters.On hitting a "bad" character and printing a usage notice, return with the required exit code, returning will automatically abort any loops you're in, any code left. On hitting a "good" character, there's no immediate action associated. After your loop, you would know the whole word is right.