- #1
mbrmbrg
- 496
- 2
C: Simple "for" loop is not working
I'm taking an online course (yay lynda!) in C/C++, and I am trying to replicate a course example that prints "Hello, World!" five times, using a simple "for" loop.
for(int i = 1; i <= 5; ++i){...}
// working.c by Bill Weinman <http://bw.org/>
#include <stdio.h>
int main( int argc, char ** argv ) {
for(int i = 1; i <= 5; ++i) {
int x = printf("Hello, World!\n") * 5;
printf("printf returned %d\n", x);
printf("%d", i);
return 0;
}
}
My program runs, but only with 1 iteration of the loop. For reading ease, I've attached a screenshot taken in Eclipse.
4. Other Potentially Relevant Information
I previously have had trouble with a dummy program that required user input. It had been a long day, so I kind of closed my eyes and pretended it was going to be fine, but I never solved that problem, either.
5. Further Work
Uninstall and reinstall everything?? I'd really rather not, but it's all I've got right now.
6. Thank you!
Homework Statement
I'm taking an online course (yay lynda!) in C/C++, and I am trying to replicate a course example that prints "Hello, World!" five times, using a simple "for" loop.
Homework Equations
for(int i = 1; i <= 5; ++i){...}
The Attempt at a Solution
// working.c by Bill Weinman <http://bw.org/>
#include <stdio.h>
int main( int argc, char ** argv ) {
for(int i = 1; i <= 5; ++i) {
int x = printf("Hello, World!\n") * 5;
printf("printf returned %d\n", x);
printf("%d", i);
return 0;
}
}
My program runs, but only with 1 iteration of the loop. For reading ease, I've attached a screenshot taken in Eclipse.
4. Other Potentially Relevant Information
I previously have had trouble with a dummy program that required user input. It had been a long day, so I kind of closed my eyes and pretended it was going to be fine, but I never solved that problem, either.
5. Further Work
Uninstall and reinstall everything?? I'd really rather not, but it's all I've got right now.
6. Thank you!
Attachments
Last edited by a moderator: