Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » scanf skews console output
scanf skews console output [message #122207] Wed, 29 September 2004 18:54 Go to next message
Eclipse UserFriend
Originally posted by: vangogh.znet.com

Eclipse Platform v3.0.1 and CDT v2.0.2 Compiler cygwin
AMD Athlon 1600 XP Windows XP

Can anyone help? I am new to eclipse and have run into a problem with the
console display when I use the C 'scanf' function as in the following demo:

/* scanf demo */
#include <stdio.h>

int main()
{
char str[80]

printf("Enter your surname: ");
scanf("%s",str);
printf("Hello Mr. %s",str);

return(0);

}
When the program is Run the console does not display anything until I input
a name. That is, the console does not display the "Enter your surname:"
prompt until after I input a surname! The following is the consoles display
when the program terminates:

Woodward

Woodward

Enter your surname: Hello Mr. Woodward
Re: scanf skews console output [message #122234 is a reply to message #122207] Thu, 30 September 2004 03:43 Go to previous message
Eclipse UserFriend
Originally posted by: johan.nosp.m.appeal.se

You need to fflush(stdout) after your call to printf(). printf() only flushes
its buffers when it prints a newline ("\n").

Also, because of https://bugs.eclipse.org/bugs/show_bug.cgi?id=27663 doing
printf() to the Eclipse console doesn't flush until printf()'s buffer becomes
full. CC yourself or vote for it if you're interested.

Cheers //Johan

Keith059 wrote / skrev:
> Eclipse Platform v3.0.1 and CDT v2.0.2 Compiler cygwin
> AMD Athlon 1600 XP Windows XP
>
> Can anyone help? I am new to eclipse and have run into a problem with the
> console display when I use the C 'scanf' function as in the following demo:
>
> /* scanf demo */
> #include <stdio.h>
>
> int main()
> {
> char str[80]
>
> printf("Enter your surname: ");
> scanf("%s",str);
> printf("Hello Mr. %s",str);
>
> return(0);
>
> }
> When the program is Run the console does not display anything until I input
> a name. That is, the console does not display the "Enter your surname:"
> prompt until after I input a surname! The following is the consoles display
> when the program terminates:
>
> Woodward
>
> Woodward
>
> Enter your surname: Hello Mr. Woodward
>
>
Previous Topic:Debug synchronization problem with the second window. Please response.
Next Topic:Troubles with External tools...
Goto Forum:
  


Current Time: Sat Jun 07 00:20:39 EDT 2025

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

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

Back to the top