【发布时间】:2022-01-09 04:21:19
【问题描述】:
我刚刚开始学习 C,这是我试图让编译器使用 gcc 运行的代码:
#include <stdio.h>
main()
{
printf("hello, world\n");
}
每次输入gcc helloworld.c(helloworld.c是源文件名),都会出现如下错误信息:
helloworld.c:1:1: error: expected identifier or '('
{\rtf1\ansi\ansicpg1252\cocoartf2580
^
helloworld.c:13:9: warning: missing terminating ' character [-Winvalid-pp-token]
printf(\'93hello, \'93);\
^
1 warning and 1 error generated.
我尝试切换到单引号并在每个字符周围加上引号,但没有任何效果。有人知道语法有什么问题吗?
【问题讨论】:
-
您从哪里得到该错误消息?您是否从一些文本程序(如 Word 或类似程序)复制代码?这些程序在文本文件中添加了奇怪的东西。
-
我正在终端上编译/gcc-ing源文件。假设一个 .out 可执行文件是否有效?我是在终端上完成的,这就是弹出消息的地方。我使用 Visual Studio 编辑器编写的代码。
-
请显示您用于编译的命令,并在您的问题中包含确切的错误消息。
-
命令:gcc helloworld.c;确切的错误消息:helloworld.c:1:1: error: expected identifier or '(' {\rtf1\ansi\ansicpg1252\cocoartf2580 ^ helloworld.c:13:9: 警告:缺少终止字符 [-Winvalid-pp- token] printf(\'93hello, \'93);\ ^ 1 个警告和 1 个错误生成。
-
这可能是我学到的最重要的一课哈哈非常感谢您的帮助!