c - 如何解决这个语法错误?(使用 C)
问题描述
我开始学习 C 编程语言并写了流行的“Hello world!” 程序。但是当我尝试执行它时,会出现
Traceback (most recent call last):
File "C:\Users\asebo\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\asebo\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "c:\Users\asebo\.vscode\extensions\ms-python.python-2021.3.680753044\pythonFiles\lib\python\debugpy\__main__.py", line 45, in <module>
cli.main()
File "c:\Users\asebo\.vscode\extensions\ms-python.python-2021.3.680753044\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 444, in main
run()
File "c:\Users\asebo\.vscode\extensions\ms-python.python-2021.3.680753044\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 285, in run_file
runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
File "C:\Users\asebo\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 267, in run_path
code, fname = _get_code_from_file(run_name, path_name)
File "C:\Users\asebo\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 242, in _get_code_from_file
code = compile(f.read(), fname, 'exec')
File "c:\Users\asebo\OneDrive\Počítač\codeblock\c.c", line 2
int main() {
^
SyntaxError: invalid syntax
这是我的完整代码:
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}
PS:我正在使用 VS 代码 IDE
解决方案
看起来你的编译输出中有一些 Python 路径,为什么?
如果我是你,我只会创建一个 C++ 控制台应用程序。在VS中,编写它并保存为C代码,给它一个文件名,即“fileName.c”并从VS文件菜单调试它。
推荐阅读
- swiftui - 致命错误:访问状态
> 外部视图.body - c - 为什么我不能在函数中指向数组的指针上使用 realloc?
- bash - 在脚本化的“oc rsh”调用中访问/传递 openshift pod 环境变量
- vb.net - VB.Net 参数计数不匹配
- c# - 安装应用程序后,它会询问我管理员凭据
- python - 为什么我不能通过 return 两次?
- sql - 查询总是给出结果,尽管它不应该
- c# - GameObject 算作已销毁但并未真正销毁
- swiftui - 如何更改 NavigationView 上的后退按钮的颜色
- python - Python Pandas:用行上的条件标记数据