c语言 - 我无法找出错误"expected ";" after top-level indicator."



I,m无法计算出错误"预期的"在顶层指示符"之后。我不能理解这个错误。

错误test.c:5:15:错误:应为";"顶级声明符之后int main(void(^;致命错误:发出的错误太多,现在停止[-ferrorlimit=]生成2个错误。make:***[:test]错误1

#include<stdio.h>
#include<cs50.h>
#include<string.h>
int main(void)
string username;

typedef struct
{
string name;
string number;
}
phnbk;
{
phnbk contact[2];
contact[0].name = "david";
contact[0].number = "123456789";
contact[1].name = "victor";
contact[1].number = "9987654321";
username = get_string("enter your name: ");
for(int i = 0 ; i < 2; i++)
{
if(strcmp(contact[i].name,username) == 0)
{
printf("your number is %s" , contact[i].number);
}
}
}

main函数必须在{}内类似于:

string username;
typedef struct
{
string name;
string number;
}
phnbk;

int main(void)
{
phnbk conta      
....

函数不能在没有大括号({}(的情况下定义。main()也不例外,它导致了错误。

因此,您必须这样定义您的主要功能:

int main(void)
{
string username;
}

稍后在{}中有另一个代码块,在任何函数之外,这是不允许的(需要引用(。您可能打算将该代码包含在main()中,如下所示:

#include<stdio.h>
#include<cs50.h>
#include<string.h>
typedef struct
{
string name;
string number;
}
phnbk;
int main(void)
{
string username;
phnbk contact[2];
contact[0].name = "david";
contact[0].number = "123456789";
//Other main() stuff
}

相关内容

最新更新