C 无法调用函数…我不';我不明白为什么函数是';没有人叫我,我错过了什么?
在程序的这个片段中,我试图调用cases_-wise函数,但是尽管我在主函数中调用了它,但这个函数没有被调用,所以,有没有人能指出我在哪里产生了错误?多谢各位C 无法调用函数…我不';我不明白为什么函数是';没有人叫我,我错过了什么?,c,struct,C,Struct,在程序的这个片段中,我试图调用cases_-wise函数,但是尽管我在主函数中调用了它,但这个函数没有被调用,所以,有没有人能指出我在哪里产生了错误?多谢各位 struct country{ char country_name[30]; int active_cases; int recovered_cases; int dead_cases; }; void cases_wise(struct country count[], int n ); i
struct country{
char country_name[30];
int active_cases;
int recovered_cases;
int dead_cases;
};
void cases_wise(struct country count[], int n );
int main(){
int i, n;
printf("***********WELCOME***********\n");
printf("Enter the number of countries: \n");
scanf("%d", &n);
struct country count[10];
for(i=0; i<n; i++){
printf("Enter the name ");
scanf("%s", &count[i].country_name);
printf("Enter the number of active cases ");
scanf("%d", &count[i].active_cases);
printf("Enter the number of recovered cases ");
scanf("%d", &count[i].recovered_cases);
printf("Enter the number of dead cases ");
scanf("%d", &count[i].dead_cases);
}
cases_wise(struct country count[], int n);
return 0;
}
struct country{
char country_name[30];
int活跃病例;
int-U病例;
int死亡病例;
};
无效案例(结构国家/地区计数[],整数n);
int main(){
inti,n;
printf(“**********欢迎***************\n”);
printf(“输入国家数目:\n”);
scanf(“%d”和“&n”);
结构国家计数[10];
对于(i=0;i在你的主要
cases_wise(struct country count[], int n);
是原型。它不是调用。若要调用函数,请删除类型名称:
cases_wise(count, n);
第一个问题是Paul Ogilvie在您的代码中给出的答案。您的程序还有其他需要改进的地方:
scanf("%s", &count[i].country_name);
不要对字符串使用&
,并添加%29s
以避免溢出:
scanf("%29s", count[i].country_name);
for循环需要另一个条件i
:i<10
,因为数组计数的大小是10
for(i=0; i<n && i < 10; i++){
// your code
}
for(i=0;icases_wise(struct count[],int n);
不是调用函数的方式。请重新阅读有关函数调用在cw中的外观的说明/书籍/课堂讲稿当我这样做时,它会抛出一个错误,说:error:expected')'在'int'之前,我如何解决这个问题?非常感谢,先生。是的,我正在修改函数章节。i@Jabberwocky是的,他以前可以这样做,但是检查n>10
而不是=10
。他可以创建一个循环,直到n10
。嘿,是的,你是对的,我事先知道计数的大小是10。