I checked the internet before posting this question, and the answer that i found was that i might have missing brackets.
在发布这个问题之前,我检查了一下互联网,我找到的答案是我可能遗漏了括号。
int main (void) {
int input = 0;
while(input != 3) {
printf("Please select an implementation :"
"\n1. Linked list implementation"
"\n2. Ring buffer implementation"
"\n3. Exit");
fflush(stdout);
scanf("%d",&input);
switch(input) {
case 1: printf("Linked List");
break;
case 2: printf("Ring Buffer");
break;
case 3: printf("Goodbye!");
break;
}
}
return 0;
}
I removed all the code inside the cases to make it all shorter, but i still get the error. More specifically :
我删除了所有的代码,以使它更短,但我仍然得到错误。更具体地说:
At the line of int main(void) {
I get the error
在int main(void)的行中,我得到了错误。
'main' is normally a non-static function [-Wmain]
At the line of the final }
I get the error :
在最后的一行,我得到了错误:
expected declaration or statement at end of input
I tried clean and refresh, building the project again and i also restarted the computer but nothing changed.
我尝试了干净和刷新,重新构建项目,我也重新启动了电脑,但没有任何改变。
Thanks a lot!
谢谢!
2 个解决方案
#1
2
Given that your .c
file is perfect, I have seen this before, the error must be in one of your header (.h
) files.
鉴于您的.c文件是完美的,我以前见过,错误必须在您的头文件(.h)文件中。
#2
1
The reason you are getting that error is that you probably declared main in some other file, whereas the compiler only expects it to exist in your .c file. You may also want to consider using a default case in your switch statement.
您得到这个错误的原因是您可能在其他文件中声明了main,而编译器只希望它存在于您的.c文件中。您可能还需要考虑在switch语句中使用默认情况。
#1
2
Given that your .c
file is perfect, I have seen this before, the error must be in one of your header (.h
) files.
鉴于您的.c文件是完美的,我以前见过,错误必须在您的头文件(.h)文件中。
#2
1
The reason you are getting that error is that you probably declared main in some other file, whereas the compiler only expects it to exist in your .c file. You may also want to consider using a default case in your switch statement.
您得到这个错误的原因是您可能在其他文件中声明了main,而编译器只希望它存在于您的.c文件中。您可能还需要考虑在switch语句中使用默认情况。