4 votes
Accepted

variable used in loop condition not modifies in loop body

Well, I had to think carefully about what the code is doing. That mostly comes from not using a best practice. Here's the best-practice guideline on whether to use a FOR loop or a WHILE loop. When ...
Cliff B's user avatar
  • 68.8k
2 votes
Accepted

Trying to Increment Characters in a String

One way would be to interpret characters 'a' to 'z' as digits in a number with base 26, start at "aaaa" (representing 0), and then adding 1 to the last string. Add or subtract 'a' for conversion ...
Blauelf's user avatar
  • 20.9k
2 votes

variable used in loop condition not modifies in loop body

The problem is that you are putting semicolons ';' at the end of your for loops. That makes them just evaluate the expression in the loop and so each would just be an infinite loop. that's bad.. you ...
UpAndAdam's user avatar
  • 1,311
2 votes
Accepted

Infinite looping in hacker 1 - water

I like that you don't want to use CS50's tools and use tools that you are going to have available everywhere outside of CS50. I was reviewing your code. I tried to solve it with a fflush(stdin) line, ...
Ricardo David Antonetti's user avatar
2 votes
Accepted

pset2 caesar, argv[1]

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 ...
Cliff B's user avatar
  • 68.8k
1 vote
Accepted

CS50x: Issue on problem Felipe´s Taqueria, program keeps asking me for input, without printing price, why?

There are three problems, though the second two are kind of redundant with one another. But since you are learning you should go through both of those fixes. I wouldn't have bothered with my answer ...
UpAndAdam's user avatar
  • 1,311
1 vote

CS50x: Issue on problem Felipe´s Taqueria, program keeps asking me for input, without printing price, why?

I think the issue is with your else statement inside of your for loop. The for loop is iterating through all of the items in your list until it finds a match to your input. So the first iteration, ...
Manford G.'s user avatar
1 vote
Accepted

In Check50 I get a Segmentation Fault, and trying myself gives me an endless loop

I don't understand why you are getting to check, or appear to be getting an infinite loop. When I ran your posted code, it immediately generated a seg fault. The problem is exposed here: for (int c =...
Cliff B's user avatar
  • 68.8k
1 vote
Accepted

Mario pyramid loop arithmetic question

Your math is correct, but your understanding of the variables in the for loop isn't. On the first run, rows = 0, not 1. Look at the for loop setup code: for (rows = 0; rows < height; rows++) ...
Cliff B's user avatar
  • 68.8k
1 vote
Accepted

Will the loop break in case the condition returns some value to the caller method in C?

"Will the loop break?" Technically speaking, no, it won't break. By using a return true statement, the entire function will immediately terminate and return a value of true to the calling code (or if ...
Cliff B's user avatar
  • 68.8k
1 vote

Will the loop break in case the condition returns some value to the caller method in C?

Yes, It will. By return keyword your program will be out of current function's scope. So it will be out of that loop.
t.m.'s user avatar
  • 158
1 vote

PS1 greedy question regarding formatting of do/while conditions

Do while behaves slightly different than while. You managed to find the exact difference :). Do while executes the code inside once and then checks your condition. That means in all cases the Do ...
Volvovics Adrian's user avatar
1 vote
Accepted

Choice of loops in C: Are the three loops exclusive or replaceable for a task

I think it is best to remember that each type of loop (and programming concept in general) is like a tool in your tool box. Just as there are many different types of hammers and screwdrivers, and you ...
Robert S. Pratt's user avatar
1 vote
Accepted

Why does this become an infinite loop?

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 ...
Cliff B's user avatar
  • 68.8k
1 vote
Accepted

Check function pset5 speller

Let's take the easy one first. Think about how check_buffer is populated. The for loop copies every char from word. The problem is that this does NOT copy the end of string marker, \0 to the end of ...
Cliff B's user avatar
  • 68.8k
1 vote

pset1 cash less, problem using for loops

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 ...
Cliff B's user avatar
  • 68.8k
1 vote
Accepted

pset1 cash less, problem using for loops

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 ...
AWTom's user avatar
  • 165
1 vote

Pset Cash CS 50 - need help

I can see a few bugs here - the one causing the infinite loop is your while loop. The condition is while (cents >= 25) but the value of cents never changes/decreases, so this condition will be ...
Jen's user avatar
  • 11
1 vote

Key looping in Vigenere

From Final Steps in the spec: Remember also that every time you encipher a character, you need to move to the next letter of k, the keyword (and wrap around to the beginning of the keyword if ...
DinoCoderSaurus's user avatar
1 vote
Accepted

pset4 recover single image

A loop is definitely the way to go, not if statements. Now, have you looked at the size of the file(s) produced? I suspect that the first file created is much larger than it should be - a ...
Cliff B's user avatar
  • 68.8k
1 vote
Accepted

PSet 1, Trying to add a loop to Water

You'd need a loop only if you want to re-query the user. If minutes does not change within the loop, the result will always be the same. Also, while (minutes < 0, minutes == 0); is an empty loop, ...
Blauelf's user avatar
  • 20.9k
1 vote
Accepted

PSET1 Credit infinite loop when checking length

The ^ operator is the Bitwise XOR operator in C as well as many languages that derive their syntax from C (including C++, Python and Java). I assume you want the power operator. There is no power ...
robert_x44's user avatar
1 vote
Accepted

Pset 4: Stuck in a loop again (all green pixels)

Your problem is with your fseek()s. You should fseek() back to beginning of the current line each time you read all the pixels of this line. You should do this n times for each line. You should ...
ChrisG's user avatar
  • 7,396
1 vote
Accepted

PSET3 Binary Search Function Infinite Loop

Seems you just misprinted. Change end = middle + 1 to start = middle + 1 and it will work just fine.
obesman's user avatar
  • 1,139
1 vote

Pset1 Greedy; problem with do-while loop

Your while loop does not end up EDIT: (Thanks to SuperNovaCoder for your intervention) The problem is that equality must be achieved ie the conditions must be >= EDIT1: while(cent_amount>=0) ...
MARS's user avatar
  • 5,169
1 vote

Problem in the do..while loop in Mario.c

The declaration of your main function needs to be as so: int main(void) { ...code... } Notice the positions of curly braces relative to the declaration and the lack of semi-colons.
Steve Bunting's user avatar

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