Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » Data input to C program
Data input to C program [message #170835] Tue, 06 June 2006 06:28 Go to next message
Eclipse UserFriend
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 Go to previous message
Eclipse UserFriend
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&section=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
>
Previous Topic:(CDT 3.1 RC2 managed build) Switch between mingw and cygwin toolchains
Next Topic:Need help for third party tool integration.
Goto Forum:
  


Current Time: Thu Jul 31 07:37:37 EDT 2025

Powered by FUDForum. Page generated in 0.03470 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top