Question: - Input from stdin a list of students, each having information about name and age - Store each student in the order read from stdin
- Input from stdin a list of students, each having information about name and age - Store each student in the order read from stdin as a node in a linked list
- Print the information about each student
If the input is empty, then print nothing. If there are more than 100 students, only print the first 100 students.
You must use the following template
https://www.cs.umb.edu/~duc/www/teaching/cs240/ optional_test_template.c
and complete the printLinkedList() function and the main() function.
SAMPLE INPUT (Each separate line is a student: name first, followed by age, separated by one or more white spaces)
John Smith 18 Jane Adams 19
OUTPUT (each student's information on a separate line as below.)
Student name: John Smith, age:18 Student name: Jane Adams, age:19
#include#include #include struct STUDENT { char *name; // store name of student int age; }; struct STUDENT_NODE { struct STUDENT std; struct STUDENT_NODE *next; }; struct STUDENT_NODE * createLinkedList(struct STUDENT a[], int n) { // create a linked list copying from an array of n students // return the linked list created // complete this function ... // ... if (n==0) return NULL; // return a NULL pointer if there is no student struct STUDENT_NODE *first_node; first_node = malloc(sizeof(struct STUDENT_NODE)); first_node->next= NULL; first_node->std = a[0]; // first student struct STUDENT_NODE *last_node; // always address of (currently) last node in the list last_node = first_node; for (int i=1; i<=n-1; i++) { // create a new node store student a[i] // extend the list to add this node struct STUDENT_NODE *new_node; new_node = malloc(sizeof(struct STUDENT_NODE)); new_node->std = a[i]; new_node->next = NULL; last_node->next = new_node; last_node = new_node; } return first_node; } void printStudent(struct STUDENT x) { // print all info of student x printf("Student name: %s, age: %d", x.name, x.age); } void printLinkedList(struct STUDENT_NODE* list) { // print the information of each student in the list, using printStudent() function above // first student in the list first, followed by 2nd student, etc. // complete this function ... // ... } int main() { // complete this function // ... } Please help me c programming.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
