Running interactive command line program [message #257061] |
Sun, 25 May 2008 02:47  |
Eclipse User |
|
|
|
Originally posted by: lbalbalba.gmail.com
Hi,
Ive just build the following simple commandline C program in Eclipse, that
asks for your name and then prints it :
#include <stdio.h>
int main()
{
char me[20];
printf("What is your name?");
scanf("%s",&me);
printf("Darn glad to meet you, %s!\n",me);
return(0);
}
But when I run it with the 'Run' button in Eclipse, it doesn't seem to
work right in the console window. It doesn't print out the "What is your
name" text, and does not appear to wait for input by the user.
Maybe there is something I am obviously doing wrong here, but what is it ?
How do I make Eclipse run the program correctly ?
Thanks in advance,
John Smith
|
|
|
Re: Running interactive command line program [message #257065 is a reply to message #257061] |
Sun, 25 May 2008 04:42   |
Eclipse User |
|
|
|
Originally posted by: subs._nospam_consertum.com
This is because of buffering in the C library. You will either need to
put a "\n" at the end of your printf, or you should fflush the output.
John Smith wrote:
>
> Hi,
>
>
> Ive just build the following simple commandline C program in Eclipse,
> that asks for your name and then prints it :
>
>
> #include <stdio.h>
> int main()
> {
> char me[20];
> printf("What is your name?");
> scanf("%s",&me);
> printf("Darn glad to meet you, %s!\n",me);
> return(0);
> }
>
>
> But when I run it with the 'Run' button in Eclipse, it doesn't seem to
> work right in the console window. It doesn't print out the "What is your
> name" text, and does not appear to wait for input by the user.
> Maybe there is something I am obviously doing wrong here, but what is it
> ? How do I make Eclipse run the program correctly ?
>
>
> Thanks in advance,
>
>
> John Smith
>
--
Derek
|
|
|
|
|
|
|
|
Re: Running interactive command line program [message #257168 is a reply to message #257160] |
Mon, 26 May 2008 13:57  |
Eclipse User |
|
|
|
Originally posted by: lbalbalba.gmail.com
Yes, fflush worked. Changing the program to :
#include <stdio.h>
int main()
{
char me[20];
printf("What is your name?");
fflush(stdout);
scanf("%s",&me);
printf("Darn glad to meet you, %s!\n",me);
return(0);
}
made it behave the same as when run on the command line.
Sorry for my ignorance, but Im not only new to Eclipse; Im new to C as
well and havent gotten any farther than using printf and scanf yet.
Thanks for the help,
Regards,
John Smith
|
|
|
Powered by
FUDForum. Page generated in 0.34245 seconds