【问题标题】:Errors when running C program in VS Code在 VS Code 中运行 C 程序时出错
【发布时间】:2021-03-24 08:58:27
【问题描述】:

当我运行这个基本的 C 程序时,它没有显示正确的输出。我用 VS Code 编写的每个程序都会发生这种情况。这是 VS Code 还是其他问题。我才刚刚开始。

代码

#include<stdio.h>

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

错误

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

【问题讨论】:

  • 那些不是 C 错误;它们似乎是您的 shell / IDE / 系统中的错误。

标签: c visual-studio-code compiler-errors


【解决方案1】:

首先,文件名中有一个空格不起作用,请尝试将其重命名为 hello_world.c

并从命令的开头和结尾删除那些&符号(&&)

比如:

gcc hello_world.c -o hello_world.o

如果你想把 .o 文件放在某个特定的地方,你可以使用/ 假设我们想把它放在当前目录的文件夹中

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-10
    • 2021-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多