Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: Apbullington18 on October 23, 2018, 05:47:38 pm

Title: Question about Loops
Post by: Apbullington18 on October 23, 2018, 05:47:38 pm
#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. 
Title: Re: Question about Loops
Post by: raynebc on October 23, 2018, 07:10:08 pm
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).
Title: Re: Question about Loops
Post by: Apbullington18 on October 23, 2018, 07:51:48 pm
That fixed it!  Thanks!