Hot answers tagged

3

This is a very, very common error for new programmers. The problem is the actual call to isalpha(). The isalpha() function takes a single char as input, but argv[1] is a string, not a char. Simply put, the code is trying to stuff a string down isalpha's throat and it chokes, resulting in a seg fault. You need to check each char in the string. Hint: a for ...


3

Both clauses of the if/else contain return statements. When a return statement is encountered, it will immediately return control to the calling program with no further processing in the current function. Since this is in main, it is terminating the program and returning control to the operating system. The code will never go any farther than the if/else. ...


2

The problem is a lack of understanding of how many of these functions work. While you would think that isalpha() would return a bool, it doesn't. Instead, it returns a number. If it is false, it returns 0, but if true, it returns a non-zero number. The problem is that the numeric value of "TRUE" is not necessarily the same as the number that is returned by ...


1

There are a couple issues here. First, there's a known issue with debug50. For certain library functions, if you "step into" the line of code with the function call, debug50 will try to step into the function itself and will go off in the weeds. In this case, you should use "step over" instead, to process that line of code by NOT skipping ...


1

You've run into a common newbie problem. The issue lies in this code: if ( isalpha ( c ) != 'true' ) The issue is with the return value of isalpha and what you're comparing it to. Let's handle the latter first. Putting true in single quotes is a problem. I'm not even sure what that will evaluate to. IF you want to compare something to true or false, ...


1

I am not a Pro, too, but the first thing I see is the "isalpha(c) != "true" -> When I recall this pset correctly, isalpha() does not return "false" or "true" but 0 or 1. But if the statement would be wrong the compiler would complain. So it must be a logical issue. However, that would be my first approach to solve this. Currently it looks like (at least for ...


1

The problem is surely in the return value of the isalpha function and the value of true, for what the condition is true both values must be equal, which apparently does not happen, keep in mind that isalpha, isupper etc return a value Nonzero in case of success, not necessarily a value of 1, to avoid this problem we can write simply: if (isalpha(p[i])) ...


1

I guess you mean if (isalpha(word[i])), with word being a char[] or char*, and i being something like an int? Could you maybe clarify your question by adding the surrounding code to your question?


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


1

Your problem is pretty simple. In a for loop, after the end of each loop, the third parameter (<increment command>) of the loop is executed, every time. for (<initialization>; <condition>; <increment command>) In your case your <increment command> is i++, so i gets incremented by 1 in each iteration. But, in your loop, after ...


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