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

I think you have it the other way around, you are getting the correct number of lines (height n) but the wrong combination of characters per line. Your code generates 4 a's and 2 #'s for each line. For this you want to work it out with pen and paper first using some of your left brain. For the bottom line (i=0), you want n+1 #'s and no a's. Taking n=8, for ...


1

The infinite loop lies here: while(j < rows) { printf("#"); (i++); } The loop depends on the value of j being updated and eventually not less than rows. Since j is never changed inside the loop, one of two things happens. Either the loop doesn't start, or if it does, it never stops. There has to be something inside the loop that ...


1

Normal practice is to use a for loop when the number of passes is well defined, either by a hard coded value or by a value contained in a variable. When the number of passes is based on a condition or a non-well-defined value, a while loop is preferred. Having said this, if you want to continue your approach, it is doable. You might want to try to write it ...


1

You need a semicolon immediately after each for loop. Otherwise, all the statements until the next semicolon are considered the body of that for loop. The compiler will complain if you put a semicolon on the same line as an empty-body, so it needs to be by itself on the next line. https://www.quora.com/What-does-a-for-loop-without-curly-braces-do Also, you ...


1

Is this strlen(plainText - 1) really what you want? You want one less than the length of plainText. This is subracting 1 from plainText and calling strlen on the result. Methinks it always returns 0, thus the loop doesn't run.


1

let's read what the loop says, "run while the condition is true, ie while h is less or equal to zero" which obviously is not fulfilled. a for does not care if you increase or decrease the index, it is more does not know until the loop is executed, you think "the loop will stop executing when h becomes negative" but you must think in terms of truth or ...


1

I've been trying to step through the code to duplicate what happens with no success, but I have a couple ideas. First, look at the following: if (plain [i] >= 66 || plain[i] <=90) //case for upper case letters This statement is ALWAYS true because of the OR operator. It should have been the AND operator, &&. If the code uses || to test for ...


1

Here's a problem: sizeof(name). name is a pointer, sizeof(a pointer) is 8. You probably want the length of name. (Think strlen included in string.h).


1

Why do you loop till j < d - 1 not j < d? For board 3*3, you miss board[0][2] so should return false for board[1][0]. However, I do not understand why you are stack in an infinite loop. You should return false. I suspect that something else might be wrong with your code. Also, please note that by most programmers goto is considered as bad style.


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