创建将学生添加到结构数组的函数时,以红色突出显示。这是整个代码
#include <stdio.h>
#include <string.h>
#include <locale.h>
struct addStudent(char name[], unsigned int age, unsigned int course, unsigned int);
struct student {
char name[50];
unsigned int age;
unsigned int course;
};
unsigned int student_counter = 0;
int main(void) {
setlocale(LC_ALL, "Rus");
struct student st[20];
strcpy_s(st[0].name, 50, "Руслан");
st[0].age = 18;
st[0].course = 1;
student_counter += 1;
for (int i = 0; i < student_counter; i++) {
printf("%s \t %d курс \t %d лет \n", st[i].name, st[i].course, st[i].age);
}
_getch();
return 0;
}
struct addStudent(char name[], unsigned age, unsigned course, unsigned age){
student res_st;
scrcpy_s(res_st, 50, name);
}
为什么我不能创建 addStudent 函数?提前致谢。
你应该看看指针和内存分配
这是一个工作示例:
并且您无法创建 addStudent 函数,因为:
在unsigned之后的函数参数中,需要写数据类型int
您不会返回您创建的结构,它是在函数内部创建的,完成后它会消失
年龄声明在参数中重复