Data input to C program [message #170835] |
Tue, 06 June 2006 06:28  |
Eclipse User |
|
|
|
Originally posted by: balaraman.objectechnology.com
Hi all,
I am experimenting using Eclipse IDE and gcc C/C++ compiler for building C
programs. I am writing a simple program like "Enter first No.:" -> scanf()
(for the first number), prinf("Enter second No.:") -> scanf() (for the 2nd
number), and find the sum and display.
When I run the program, printf() for the prompt, "Enter first No.:" does
not appear. The console is blank. I enter the value for the first No.; no
prompt for second number "Enter second No.:", but I go ahead and enter
value for second number. The values are accepted. Then the sum is
displayed, now the prompts for first number and second number are printed.
It seems, the program is ready for scanf only. printf works after all the
scanf's. What is the problem? How do I fix it? Can anyone here help me?
Balaraman
|
|
|
Re: Data input to C program [message #170879 is a reply to message #170835] |
Tue, 06 June 2006 09:14  |
Eclipse User |
|
|
|
Classic problem ;)
It's likely because the output is being buffered and the buffer does not get
flushed until your program has finished running. You can prevent any
buffering by doing this (just once) at the beginning:
setbuf(stdout, NULL);
Then your print statements should print when you want them. The other option
is to flush selectively after each printf(), using fflush(stdout);
here's a man page for setbuf:
http://man.linuxquestions.org/?query=setbuf§ion=0&am p;type=2
"S Balaraman" <balaraman@objectechnology.com> wrote in message
news:7a3714bbc6b5f5bef31dec92fa69d61a$1@www.eclipse.org...
> Hi all,
>
> I am experimenting using Eclipse IDE and gcc C/C++ compiler for building C
> programs. I am writing a simple program like "Enter first No.:" -> scanf()
> (for the first number), prinf("Enter second No.:") -> scanf() (for the 2nd
> number), and find the sum and display.
> When I run the program, printf() for the prompt, "Enter first No.:" does
> not appear. The console is blank. I enter the value for the first No.; no
> prompt for second number "Enter second No.:", but I go ahead and enter
> value for second number. The values are accepted. Then the sum is
> displayed, now the prompts for first number and second number are printed.
> It seems, the program is ready for scanf only. printf works after all the
> scanf's. What is the problem? How do I fix it? Can anyone here help me?
>
> Balaraman
>
|
|
|
Powered by
FUDForum. Page generated in 0.03470 seconds