We changed our privacy policy. Read more.

Hot answers tagged

2

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 ...


1

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. ;-)


1

The actual problem isn't in the isdigit statement. It's in the for statement. for(int i = 0, n = (strlen(argv[1])); i < n; i++) If there is no parameter, then argv[1] 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 ...


1

Its a simple and common issue with new programmers. ;-) Yes, argv[] is an array of strings. So, argv[1] is a string. Now, say that argv[1] contains the string "cat". Then argv[1][0] contains the char 'c', argv[1][1] contains 'a', argv[1][2] contains 't' and argv[1][3] contains the end of string marker, '\0'. That last one is very important, ...


1

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.


1

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[1][0] would point to the first character of the second argument.


1

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. ;-)


Only top voted, non community-wiki answers of a minimum length are eligible