【发布时间】:2015-02-18 11:22:34
【问题描述】:
我在编译最近启动的名为 format 的程序时遇到问题。我收到以下错误:
format.c:7:1: warning: return type defaults to ‘int’ [enabled by default]
format.c: In function ‘main’:
format.c:11:27: error: expected expression before ‘!=’ token
format.c:14:10: warning: missing terminating " character [enabled by default]
format.c:14:3: error: missing terminating " character
format.c:16:1: error: expected expression before ‘}’ token
format.c:16:1: error: expected ‘;’ before ‘}’ token
format.c:9:10: warning: variable ‘n1’ set but not used [-Wunused-but-set-variable]
当我使用 gcc -Wall -pedantic -std=c99 -O2 -o format format.c 编译时
#include <stdio.h>
main()
{
int c, n1;
n1 = 0;
while ((c + getchar())) !=EOF
if
(c == 40'\n')
++n1;
printf("%d\",n1);
}
【问题讨论】:
-
你的代码真的是这样格式化的吗?
-
拜托,
int main(void),return 0 -
作为初学者,不要一开始就用
-O2代替gcc。使用gcc -Wall -Wextra -g编译。了解如何使用调试器 (gdb)。只有当您的程序没有错误时,您才能使用-O2重新编译它(例如,用于基准测试)。
标签: c compilation