Better way to go about it
This commit is contained in:
35
Q1.c
35
Q1.c
@@ -5,34 +5,21 @@
|
|||||||
typedef struct Student {
|
typedef struct Student {
|
||||||
int id;
|
int id;
|
||||||
char name[30];
|
char name[30];
|
||||||
double grade;
|
double grades;
|
||||||
|
struct Student *next;
|
||||||
} Student;
|
} Student;
|
||||||
|
|
||||||
typedef struct Node {
|
// Create a student node
|
||||||
Student student;
|
Student *create_student(int id, char *name, double grades) {
|
||||||
struct Node* next;
|
Student *student = (Student*)malloc(sizeof(Student));
|
||||||
} Node;
|
student->id = id;
|
||||||
|
strcpy(student->name, name);
|
||||||
Node* newNode(const int id, const char* name, const double grade) {
|
student->grades = grades;
|
||||||
Node* node = (Node*)malloc(sizeof(Node));
|
student->next = NULL;
|
||||||
node->student.id = id;
|
return student;
|
||||||
strcpy(node->student.name, name);
|
|
||||||
node->student.grade = grade;
|
|
||||||
node->next = NULL;
|
|
||||||
return node;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void insert_student(Student *student) {}
|
||||||
void printStudents(Node* head) {
|
|
||||||
Node* current = head;
|
|
||||||
while (current != NULL) {
|
|
||||||
printf("Student ID: %d\n", current->student.id);
|
|
||||||
printf("Student Name: %s\n", current->student.name);
|
|
||||||
printf("Student Grade: %f\n", current->student.grade);
|
|
||||||
current = current->next;
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user