1

I compiled a simple program in C (it does the sum of 2 numbers), by doing :

M-x compile RET
gcc -dummy.c -o dummy
M-x shell RET
./dummy

I get a prompt for the first number I can enter, then nothing is happening. I mean I can enter the first number, do RET, enter the second number (even though I don't have the prompt for this one) and I can get the result with Ctrl-D. So, very ugly. Any idea what is happening under the hood and what I should do to improve that? Thanks

here is the code :

int main()
{
    int nb1,nb2;
    printf("please enter nb1");
    scanf("%d \n", &nb1);
    printf("please enter nb2");
    scanf("%d \n", &nb2);
    printf("the sum:");
    printf("%d + %d = %d", nb1, nb2, nb1 + nb2);
    return 0;
}
loukios
  • 815
  • 1
  • 8
  • 19
  • 2
    One solution is to use M-x term or M-x ansi-term. This will give you a real terminal emulator instead of shell-mode. – Qudit Nov 01 '16 at 09:31
  • @Qudit : please post your comment as an answer. – Dan Nov 01 '16 at 13:52
  • The problem with `shell-mode` is that it needs you to send and read full lines. So, when you do `printf()` it doesn't know the program finished printing. If you add `\n` to your `printf()`, I believe it will work in `shell-mode`. – wvxvw Nov 01 '16 at 15:29

1 Answers1

2

One solution is to use M-x term or M-x ansi-term. This will give you a real terminal emulator instead of shell-mode.

Qudit
  • 828
  • 8
  • 16
  • Thanks, one thing I have to do now is making the shell buffer open in place of the compilation window... – loukios Nov 01 '16 at 16:59
  • I'm not entirely sure what you want to accomplish. Maybe you could make it a new question though – Qudit Nov 01 '16 at 17:31
  • Yeah, it was not that clear, I've opened a new topic (http://emacs.stackexchange.com/questions/28354/open-the-shell-buffer-in-the-same-frame-as-compilation-buffer-c-compilation). Thanks – loukios Nov 02 '16 at 15:39