User forums > Using Code::Blocks

Question about Loops

(1/1)

Apbullington18:
#include <stdio.h>
main()
{
int x = 0;
while (x < 5)
{
    printf(" ",x,"\n");
    x++;
}
return 0;
}

I can't get this program to run in CodeBlocks.  It's just a simple while loop, but nothing comes out when run.  I'm new to coding so forgive me if i'm naive. 

raynebc:
That printf statement isn't doing what you think it is, it's just printing space characters.  You'll probably want to do printf(" %d\n", x); instead.  If you enabled all the optional warnings in your compiler, you would likely get a warning that you passed too many arguments (ie, x and "\n" being ignored because the format string didn't call for the use of any additional arguments).

Apbullington18:
That fixed it!  Thanks!

Navigation

[0] Message Index

Go to full version