[英]Not able to call the function…I don't understand why the function isn't being called, what am I missing?
在這個程序片段中,我試圖調用 case_wise function,但盡管我在主 function 中調用它,但這個 function 在哪里創建錯誤,所以我不能在哪里創建錯誤? 謝謝
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;
}
在你的主要:
cases_wise(struct country count[], int n);
是一個原型。 這不是一個電話。 要調用 function,請刪除類型名稱:
cases_wise(count, n);
第一個問題是 Paul Ogilvie 在您的代碼中的回答。 您的程序還有其他需要改進的地方:
scanf("%s", &count[i].country_name);
不要將&
用於字符串,並添加%29s
以避免溢出:
scanf("%29s", count[i].country_name);
您的 for 循環需要i
的另一個條件: i < 10
,因為數組count
的大小為 10。
for(i=0; i<n && i < 10; i++){
// your code
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.