So i have to write this function that creates a node to hold a student record specified by siid(student_id), lastname, firstname and gpa. After creating the new node i have to insert it to the proper list in the hash table pointed by hashtable. The memory of the new node is dynamically allocated. my question is: Two students cannot have the same student_id , so if the inserted record has the same student_id with an existing record in the list my program should print to the standard output:
insertion failed: student_id xxxxxx already exists
where xxxxxx is the student_id value. my second question: If the insertion of a record is successful it should print:
.
record xxxxx inserted
this is what i have so far:
Code:void insertRecord(Student **hashtable, unsigned int sid, char *lastname, char *firstname, float gpa); { Student *p, *head; p=(student *) malloc(sizeof(student)); int i; Student *s;/*node*/ if (s==NULL) { s->student_id =sid; strcpy(s->firstname,firstname);/*copying first and lastname to s*/ strcpy(s->lastname,lastname); s->gpa=gpa; hashtable[sid%M] = s; } else {/*s != NULL;*/ s = s-> next; s->student_id=sid; } if (student_id = s) { printf("insertion failed: student_id %d already exists\n", sid); } printf("record %d inserted", sid);



LinkBack URL
About LinkBacks


