Home > Software design >  My C program won't print anything even though I tried everything I read on Internet
My C program won't print anything even though I tried everything I read on Internet

Time:10-03

My Hello World program doesn't give any output. I have been struggling for a week trying to do different things mentioned on internet such as:

  • Adding \n at the end (as printf("Hello World\n");)
  • fflush(stdio);
  • getch();
  • I tried reinstalling C compiler
  • I went from ming64 to ming32
  • I even tried compiling it with g
  • I tried it out on VS code too using command prompt

But no matter what, still I won't get output. The code is as follow:

#include <stdio.h>
int main(void) {
  printf("Hello World\n");
  return 0;
}

The output on console I get is as follow:

[Running] cd "g:\C WorkSpace\" && gcc Test.c -o Test && "g:\C WorkSpace\"Test
 
[Done] exited with code=0 in 0.453 seconds

The code does compile and creates an .exe file.
The executable file runs and doesn't print anything.

Edit: I have tried it on comamand prompt too but still it won't give output This is what it looks like

 Directory of G:\C WorkSpace

02-10-2021  06.34 PM    <DIR>          .
02-10-2021  06.34 PM    <DIR>          ..
02-10-2021  06.28 PM    <DIR>          .vscode
21-09-2021  08.22 AM                82 Hello World.c
02-10-2021  06.33 PM                83 Test.c
02-10-2021  06.34 PM            40,764 Test.exe
21-09-2021  09.57 AM    <DIR>          TestProjects
               3 File(s)         40,929 bytes
               4 Dir(s)  510,360,821,760 bytes free

G:\C WorkSpace>gcc test.c -o Test

G:\C WorkSpace>.\Test

G:\C WorkSpace>g   Test.c -o Test

G:\C WorkSpace>.\Test

G:\C WorkSpace>

Edit 2: It has been pointed out that there must be an issue with my toolchain so I am updating the question with how I have installed it.

I downloaded the setup from https://sourceforge.net/projects/mingw/files/OldFiles/ downloaded the latest version of mingw-get-setup.exe(86.5kB)

I ran the setup it downloaded things, after that it took me to MinGW Installation Manager

I checked mingw32-base, mingw32-gcc-g ,mingw32-gcc-objc and updated catalog I am assuming it meant installation because it downloaded some files.

After that I setup the environment PATH as C:\MinGW\bin

Edit 4: I have tried running it in command prompt in all possible ways but it won't work

G:\C WorkSpace>gcc Test.c -o Test

G:\C WorkSpace>Test.exe

G:\C WorkSpace>.\Test.exe

G:\C WorkSpace>./Test.exe
'.' is not recognized as an internal or external command,
operable program or batch file.

G:\C WorkSpace>

CodePudding user response:

In windows operating system, when file compiled then its converted into executable format (.exe)

G:\C WorkSpace>gcc test.c -o Test  //to compile

G:\C WorkSpace>Test.exe  //to execute

you just have to change .\Test to Test.exe

CodePudding user response:

Please go to the setting of VS code; Click on the extension settings on the left side; Search there terminal; Now find the option "run on terminal" turn it on.

CodePudding user response:

Simply type Test instead of .\Test, if you’re on windows

  • Related