简体   繁体   中英

Errors when running C program in VS Code

When i run this basic C program, it's not showing proper output. It is happening with every program I am writing in VS Code. Is this a problem with VS Code or anything else. I am just starting out.

CODE

#include<stdio.h>

int main() {
    printf("hello world");
    return 0;
}

ERROR

PS C:\Users\Dev\Documents\Prog vsc> cd "c:\Users\Dev\Documents\Prog vsc\" && gcc hello world.c -o hello world && "c:\Users\Dev\Documents\Prog vsc\"hello world
At line:1 char:39
+ cd "c:\Users\Dev\Documents\Prog vsc\" && gcc hello world.c -o hello world && "c: ...
+                                       ~~
The token '&&' is not a valid statement separator in this version.
At line:1 char:75
+ cd "c:\Users\Dev\Documents\Prog vsc\" && gcc hello world.c -o hello world && "c: ...
+                                                                           ~~
The token '&&' is not a valid statement separator in this version.
At line:1 char:78
+ cd "c:\Users\Dev\Documents\Prog vsc\" && gcc hello world.c -o hello world && "c: ...
+                                                                              ~~~
Expressions are only allowed as the first element of a pipeline.
At line:1 char:112
+ ... ents\Prog vsc\"hello world
+                    ~~~~~
Unexpected token 'hello' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : InvalidEndOfLine

well first off, the file name has a space in it which won't work, try renaming it to hello_world.c

and remove those ampersands(&&) from the start and end of the command

So like:

gcc hello_world.c -o hello_world.o

And if you want to put the.o file somewhere specific you can use / lets say we want to put this in a folder in the current directory

gcc hello_world.c -o./test/hello_world.o

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM