PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Not displaying numbers?

This may be simple, but it is a major problem I have been having:

Code:

#include <stdio.h>
main()
{
int ctr = 5;
printf(" %d", ctr);

system("PAUSE");
return 0;
}


When I run the program, the number 5 does not display. I am used to using "cout" with C++, can someone help me out?
simonjacobs · 06 Jul 2003, 09:54 UTC
That should work on msdos I reckon, unless I'm missing something.
simonjacobs wrote:
That should work on msdos I reckon, unless I'm missing something.


That's exactly what I want it to do. But for some reason, it does not print 5 like its supposed to. Could it have anything to do with my gcc compiler?
This is just a guess, but it's most likely because the comp pauses before the output buffer has a chance of being flushed.

try putting this after the printf() and before the system():

Code:
fflush(stdout);
I think I am having some problems with my compiler.

I typed in this:
Code:

#include <stdio.h>
main()
{

printf("DOES THIS WORK?\n");


system("PAUSE");
return 0;
}


and all it did was say "press a key to continue..."

Oh well, I'll just reinstall my compiler.
Like I said, you have to flush the output buffer; otherwise it'll print whatever you printf'ed after the system() call and right before the dos box closes. Run the program from a command prompt and you'll see what I mean.

What I showed you worked without any problems in gcc.