该楼层疑似违规已被系统折叠隐藏此楼查看此楼
给函数定义参数的时候遇到困难了,知道的告诉我一下具体应该怎么发送和接收参数。
#include
#include
struct Student
{
int age;
float score;
char name[100];
};
void k((*pArr[0]).score, int len;)
{
struct Student t;
int i;
for (i = 0; i < len - 1; i++)
{
if (pArr[i].score > pArr[i - 1].score)
{
t = pArr[i];
pArr[i] = pArr[i - 1];
pArr[i - 1] = t;
}
}
}
int main (void)
{
int len;
struct Student * pArr;
int i;
int j;
k((*pArr[0]).score, len);
printf("请输入学生个数:\n");
printf("amount=");
scanf_s("%d", &len);
pArr = (struct Student *)malloc(len * sizeof(struct Student));
//输入
for (i = 0; i < len; i++)
{
printf("请输入第%d个学生的信息:\n", i+1);
printf("age = ");
scanf_s("%d", &pArr[i].age);
printf("name = ");
scanf_s("%s", pArr[i].name, 10);
/*
1.name是数组名,本身就已经是数组首元素的地址,所以pArri[i].name不能写成&pArr[i].name
2.由于scanf_s的防溢出机制,所以这个地方要加上字符位数,但此特性只有微软实行,所以可移植性会降低。
*/
printf("score =");
scanf_s("%f", &pArr[i].score);
}
// 输出
printf("你输入的信息是:\n\n\n");
for (i = 0; i < len; ++i)
{
printf("第%d个学生的信息是:\n", i + 1);
printf("age = %d\n", pArr[i].age);
printf("name = %s\n", pArr[i].name);
printf("score =%f\n", pArr[i].score);
}
return 0;
}