當我試圖編譯此代碼時,出現錯誤:轉換爲非標量類型請求。此錯誤涉及行:請求的非標量類型C
func(record);
我可以知道我的代碼中出了什麼問題嗎?
#include <stdio.h>
#include <string.h>
struct student
{
int id;
char name[30];
float percentage;
};
void func(struct student record);
int main()
{
struct student record[2];
func(record);
return 0;
}
void func(struct student record[]) {
int i;
record[0].id=1;
strcpy(record[0].name, "lembu");
record[0].percentage = 86.5;
record[1].id=2;
strcpy(record[1].name, "ikan");
record[1].percentage = 90.5;
record[2].id=3;
strcpy(record[2].name, "durian");
record[2].percentage = 81.5;
for(i=0; i<3; i++)
{
printf(" Records of STUDENT : %d \n", i+1);
printf(" Id is: %d \n", record[i].id);
printf(" Name is: %s \n", record[i].name);
printf(" Percentage is: %f\n\n",record[i].percentage);
}
}
修正你的函數聲明,它應該包括'[]'如果你傳遞的記錄數組。 –