gpt4 book ai didi

c - C 中请求的非标量类型

转载 作者:太空宇宙 更新时间:2023-11-04 02:06:52 25 4
gpt4 key购买 nike

当我尝试编译这段代码时,出现错误:请求转换为非标量类型。此错误涉及行:

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);
}

}

最佳答案

func 的原型(prototype)说:

void func(struct student record); 

应该是:

void func(struct student record[]);

关于c - C 中请求的非标量类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19729852/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com