0

I'm learning C and everything is going wrong. The very simple programs I'm compiling are spawning three of the same processes all of which I can't kill — not through taskmanager, taskkill, or ctrl+c. For instance this program:

#include <stdio.h>

int main() {
    int a = 0;
    printf("Enter a number: ");
    scanf("%d", &a);
    printf("%d", a);
    return 0;
}

will only work if I write it in vim and run it with cmd prompt NOT git bash. Yet if I write the same program in atom text editor and run it with cmd prompt it doesn't work. The cmd prompt becomes unresponsive to further commands as well as git bash and it spawns three unkillable processes.

What's going wrong? How do I get sane behaviour?

chqrlie
  • 131,814
  • 10
  • 121
  • 189
user5800226
  • 147
  • 2
  • 6
  • Is it possible that atom is using a wrong character encoding? – Marco Altieri Jan 17 '16 at 02:33
  • Could this be it?? How do I check? – user5800226 Jan 17 '16 at 02:34
  • I just tried writing it in notepad++ and it didn't work. – user5800226 Jan 17 '16 at 02:39
  • I just tried it on CodingGround and it works fine. http://www.tutorialspoint.com/compile_c_online.php I copied your code, pasted it there, compiled the program, and then executed it. What are you doing to compile and run the program? – jdigital Jan 17 '16 at 02:41
  • jdigital - I'm compiling using g++. The only difference is the directory and text editor. If I compile it on desktop it works but if I go into a folder on desktop and compile/execute it the command prompt no longer accepts input – user5800226 Jan 17 '16 at 02:45
  • bash doesn't include the current directory in the path, when running your program from bash, you should include the path of the executable. you might be running a different program rather than the one you just compiled. – jdigital Jan 17 '16 at 02:55
  • jdigital that's cpp I'm using .c. Also it's not the code it's the directory I'm compiling in I think. – user5800226 Jan 17 '16 at 02:57
  • This is puzzling! Can you provide a screenshot of your hung terminal window? – chqrlie Jan 17 '16 at 03:01
  • http://i.imgur.com/ZgMcvFg.png – user5800226 Jan 17 '16 at 03:13
  • compiling the program that works on desktop with a different name causes it to hang too btw. – user5800226 Jan 17 '16 at 03:28
  • This is a complete stab in the dark, but does it do anything different if you rename the "dev" folder? (I'm wondering if msys is doing something silly to emulate `/dev` or something like that) – Score_Under Jan 17 '16 at 04:07
  • 1
    Can you show the compilation command and messages? – chqrlie Jan 17 '16 at 04:16
  • 1
    Another try: can you add `fflush(stdout);` after `printf("Enter a number: ");` ? – chqrlie Jan 17 '16 at 04:20
  • 3
    @user5800226: This may sound odd but do you use Avast antivirus? The unkillable tasks sound like a common Avast problem with false-positives. – Blastfurnace Jan 17 '16 at 04:41
  • @Blastfurnace yes I use Avast and will attempt to turn it off and try tomorrow (on mobile) – user5800226 Jan 17 '16 at 05:09
  • @Blastfurnace just did some googling and found an article that says avast caused 3 unkillable processes. Exactly like my situation https://forum.avast.com/index.php?topic=180904.0 – user5800226 Jan 17 '16 at 05:15
  • 1
    @user5800226: Yeah, I've been flagging duplicate reports of the Avast problem in [this other SO question](https://stackoverflow.com/questions/33690697/running-my-c-code-gives-me-a-blank-console). It's being reported by gcc and Visual C++ users. – Blastfurnace Jan 17 '16 at 05:22

0 Answers0