It's always the problems that hide in plain sight that get us! ;-)
isdigit() is working exactly as expected. If a character is a digit, it returns a non-zero (not necessarily 1, try printing the return value as an int) if true and returns 0 if false. There's no need to use this function in any special way as was suggested.
The problem here appears to be a ...
In other words, the isdigit() function (and all of it's issomething() cousins) takes a single char as input. If you pass it a string, it chokes and generates a seg fault.
Otherwise, @MARS gave a great explanation. ;-)
The actual problem isn't in the isdigit statement. It's in the for statement.
for(int i = 0, n = (strlen(argv)); i < n; i++)
If there is no parameter, then argv doesn't exist. So, strlen throws a seg fault.
The code needs to check argc before it does anything with argv.
If this answers your question, please click on the check mark to accept. Let's ...
Its a simple and common issue with new programmers. ;-)
Yes, argv is an array of strings. So, argv is a string. Now, say that argv contains the string "cat". Then argv contains the char 'c', argv contains 'a', argv contains 't' and argv contains the end of string marker, '\0'. That last one is very important, ...
It seems correct because it is. The 'expected expression' error is almost always because of misplaced, missing or extra curly braces or parentheses.
Is it possible that you're editing one version of the source code and trying to make another version, or filename?
Also, recommend that you run your code through style50 to clean up formatting a bit.
argv is a list of arguments introduced from the comand line. If you want to itterate through ever char in a particular argument you can do it by: argv[x][i] where x is the argument number and 'i' every character of that argument. For examble argv would point to the first character of the second argument.
isalpha() takes a single character. When you try to jam a complete string down its throat, it chokes and coughs up a seg fault. You need to loop through the string and test each char individually.
If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)