所以我正在学习数据结构,并且对 C 非常陌生。我正在尝试制作一个接受学生 ID 和课程编号的函数,输出将是学生姓名和课程名称。我目前被困在输入部分。这是我到目前为止的代码:
typedef struct Student Student;
typedef struct Course Course;
typedef struct Node Node;
typedef struct Node* NodePtr;
struct Student{
int id;
char name[30];
double gpa;
int ch;
};
struct Course{
int id;
char code[10];
char name[30];
int ch;
};
void displayStudents() {
struct Student students[10]={
{1, "ahmed" ,3.6,43},
{2, "mohamed", 3.2, 40},
{3,"hassan", 3.0, 41},
{4, "hossam", 2.5, 35},
{5, "hany", 2.3, 32},
{6, "hala", 2.7, 37},
{7, "hana", 2.8, 33},
{8, "ramadan",3.8,46},
{9, "sameh",3.7,43},
{10, "nour",3.3,42}
};
for(int i=0; i<10; i++) {
printf("%d,%s,%lf, %d", students[i].id, students[i].name, students[i].gpa, students[i].ch);
printf("\n");
}
}
void displayCourses() {
struct Course courses[3] = {
{30, "CS212", "DataStructure", 3},
{40, "CS233", "Architecture", 3},
{50, "GM300", "Multimedia", 3}
};
for (int i=0; i<3; i++) {
printf("%d - %s - %s - %d", courses[i].id, courses[i].code, courses[i].name, courses[i].ch);
printf("\n");
}
}
void Registeration(struct Student student, *struct Course courses) {
printf("Select a student: \n");
gets(student.name);
printf("Enter his ID: ");
scanf("%d", &student.id);
printf("Select a course: ");
scanf("%d",&course.id);
}
我在注册功能中遇到错误。我尝试删除指针但它引起了其他问题,我也尝试了很多其他东西但无济于事。
这是错误:
||=== Build: Debug in Data Structure Project (compiler: GNU GCC Compiler) ===|
C:\Users\Shiko\Desktop\C Tutorials\Data structure project\main.c|155|error: expected declaration specifiers or '...' before '*' token|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
这不是有效的语法
void Registeration(struct Student student, *struct Course courses)
我怀疑你的意思是
void Registeration(struct Student student, struct Course courses)
要么
void Registeration(struct Student student, struct Course *courses)
取决于您是要将结构作为 arg 还是指向结构的指针传递。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句