[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
capturing user input for program run in Emacs?
From: |
patrol |
Subject: |
capturing user input for program run in Emacs? |
Date: |
Wed, 08 Dec 2010 15:16:33 -0000 |
User-agent: |
G2/1.0 |
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
- capturing user input for program run in Emacs?,
patrol <=