It looks like you aren't compiling your source code as an executable and/or you are naming the output a.out
which is not a valid executable. Hence it cannot be run. Please provide us with the command line you're running when you build your code. Also please provide a link to the tutorial you're using and confirm what tools you've installed in VS Code to compile for C. Are you actually trying to compile C or C++ code. Either one requires additional tools.
Why is VS Code unable to run the code?
I've been trying to learn C as a beginner from online tutorials. However when I tried to run a simple code "Hello World!" the compiler seems unable to process it. It keeps sending back an error like this : PS C:\Users\puran\OneDrive\Desktop\C Tutorials> ./a.out
./a.out : The term './a.out' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ ./a.out
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: (./a.out:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I've set my environment variables correctly i believe.
Windows for business | Windows Client for IT Pros | User experience | Other
2 answers
Sort by: Most helpful
-
Michael Taylor 60,161 Reputation points
2024-09-06T02:39:33.2+00:00 -
Neuvi Jiang 1,540 Reputation points Microsoft External Staff
2024-09-06T08:14:31.4533333+00:00 Hi Vaishak Upadhyaya,
Thank you for posting in the Q&A Forums.
Make sure your C program is compiled:
Using the GCC compiler (or any other compiler of your choice), you should be able to compile your hello.c file. For example, run it from the command line:
bash
gcc hello.c -o hello.exe
This will compile hello.c and produce an executable file called hello.exe.
Run your program from the command line:
If you are using the Windows command prompt (cmd) or PowerShell, you should run the name of the executable file directly, rather than using the . / prefix. In your example, you should run:
bash
hello.exe
instead of . /a.out.
Best regards
NeuviJ
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.