all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* capturing user input for program run in Emacs?
@ 2010-06-30 18:47 patrol
  2010-06-30 22:28 ` Tim X
  0 siblings, 1 reply; 2+ messages in thread
From: patrol @ 2010-06-30 18:47 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

I ran a simple C program from within Emacs using the shell command
(M-!). The program requires user input.

Here's the program:

#include <stdio.h>

char firstInitial, middleInitial, lastInitial;
int age;

main()
{
  printf("Input your three initials (first, middle, and last) and your
age:   ");
  scanf("%c%c%c%i", &firstInitial, &middleInitial, &lastInitial,
&age);
  printf("\nGreetings %c.%c.%c. %s %i.\n",
	 firstInitial, middleInitial, lastInitial,
	 "Next year your age will be", age + 1);
}

And this is the output I get:

Input your three initials (first, middle, and last) and your age:   ^M

Greetings ^@.^@.^@. Next year your age will be 1. ^M

The program just outputs this and doesn't stop to give me a chance to
input the information. I believe the ^M stands for RET, so it looks
like Emacs is somehow automatically "feeding RET" to the program, I'm
guessing??? And I have no idea what ^@ means.

I also tried starting a separate subshell using M-x shell. It works
"better", but still not right. When I activate the program by typing
its filename (which is Initials), I don't see the user prompt (i.e.,
"Input your three initials..."). It just reprints the file name like
so:

c:\cprograms>Initials
Initials

So then I do the input anyway (e.g., ABC30), press RET, then I get:

Input your three initials (first, middle, and last) and your age:
Greetings A.B.C. Next year your age will be 31.

So, I guess it's kind of working, but the user input part is still
messed up. Incidentally, the program works fine from the console
(command) prompt, but I'd like to be able to run it from within Emacs,
too. Can anyone tell me what the problem is?

Thanks


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: capturing user input for program run in Emacs?
  2010-06-30 18:47 capturing user input for program run in Emacs? patrol
@ 2010-06-30 22:28 ` Tim X
  0 siblings, 0 replies; 2+ messages in thread
From: Tim X @ 2010-06-30 22:28 UTC (permalink / raw)
  To: help-gnu-emacs

patrol <patrol_boat@hotmail.com> writes:

> Hi,
>
> I ran a simple C program from within Emacs using the shell command
> (M-!). The program requires user input.
>
> Here's the program:
>
> #include <stdio.h>
>
> char firstInitial, middleInitial, lastInitial;
> int age;
>
> main()
> {
>   printf("Input your three initials (first, middle, and last) and your
> age:   ");
>   scanf("%c%c%c%i", &firstInitial, &middleInitial, &lastInitial,
> &age);
>   printf("\nGreetings %c.%c.%c. %s %i.\n",
> 	 firstInitial, middleInitial, lastInitial,
> 	 "Next year your age will be", age + 1);
> }
>
> And this is the output I get:
>
> Input your three initials (first, middle, and last) and your age:   ^M
>
> Greetings ^@.^@.^@. Next year your age will be 1. ^M
>
> The program just outputs this and doesn't stop to give me a chance to
> input the information. I believe the ^M stands for RET, so it looks
> like Emacs is somehow automatically "feeding RET" to the program, I'm
> guessing??? And I have no idea what ^@ means.
>
> I also tried starting a separate subshell using M-x shell. It works
> "better", but still not right. When I activate the program by typing
> its filename (which is Initials), I don't see the user prompt (i.e.,
> "Input your three initials..."). It just reprints the file name like
> so:
>
> c:\cprograms>Initials
> Initials
>
> So then I do the input anyway (e.g., ABC30), press RET, then I get:
>
> Input your three initials (first, middle, and last) and your age:
> Greetings A.B.C. Next year your age will be 31.
>
> So, I guess it's kind of working, but the user input part is still
> messed up. Incidentally, the program works fine from the console
> (command) prompt, but I'd like to be able to run it from within Emacs,
> too. Can anyone tell me what the problem is?
>

This looks like a buffering issue to me. 

Try ensuring you flush your output before attempting to read input. 

Tim


-- 
tcross (at) rapttech dot com dot au


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-06-30 22:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-30 18:47 capturing user input for program run in Emacs? patrol
2010-06-30 22:28 ` Tim X

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.