I am fairly new to C coding and cannot get a simple C hello world code to work with Visual Studio Code. The code looks like this:
#include <stdio.h>
int main() { // printf() displays the string inside quotation printf("Hello, World!"); return 0;
} and I get two error messages:
line 2: syntax error near unexpected token `('
line 2: `int main() {'Any suggestions on what can be going wrong?
91 Answer
Here is a screenshot of the C code in the question (hello.c) running correctly in Visual Studio Code. In order to run hello.c in Code Runner right-click the code and select Run Code.
Please note in the left pane that I have the C/C++ extension and the Code Runner extension installed in Visual Studio Code. Please note in the tabs below the menu bar that the C code has been saved in a file named hello.c. Please note in the bottom pane that Code Runner executed this C code by running the following command:
cd "/home/karel/Desktop/" && gcc tempCodeRunnerFile.c -o tempCodeRunnerFile && "/home/karel/Desktop/"tempCodeRunnerFile 1