Hello I am just trying to get a little nudge in the right direction I cant make
ID: 3657018 • Letter: H
Question
Hello I am just trying to get a little nudge in the right direction
I cant make it into the lab due to work.
/*
Complete insertStudents and deleteStudents functions in the skeleton program.
The output of the program should be like:
sid=001,name=John
sid=002,name=Joan
sid=003,name=Jack
sid=001,name=John
sid=003,name=Jack
*/
#include "ex6.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(){
Snodeptr students;
//Create the dummy node
makenullStudents(&students);
struct studentType student1,student2,student3;
strcpy(student1.sid,"001");
strcpy(student1.sname,"John");
strcpy(student2.sid,"002");
strcpy(student2.sname,"Joan");
strcpy(student3.sid,"003");
strcpy(student3.sname,"Jack");
insertStudents(student1,students);
insertStudents(student2,students);
insertStudents(student3,students);
printStudents(students);
deleteStudents(student2,students);
printStudents(students);
return 0;
}
Snodeptr sAlloc(void) {
return (Snodeptr) malloc(sizeof(struct snode));
}
void makenullStudents(Snodeptr *students) {
(*students)=sAlloc();
}
void insertStudents(struct studentType x, Snodeptr students) { --- I am tryingto understand what ineed to put into step make it work---can you provide some helpful hints--what i have in here is not working
char line[80];
printf("Enter Student Id: ");
getline(line,sizeof(line));
scanf(line,"%s",x.sid);
printf("Type in Student Name: ");
getline(line,sizeof(line));
scanf(line,"%s",x.sname);
if (insertStudents(x,students) == 0)
printf("Student s has been inserted", x.sid);
else
printf("Student s already exists", x.sid);
}
void deleteStudents(struct studentType x, Snodeptr students) { --- I am trying to understand what i need to put into step make it work---can you provide some helpful hints----what i have in here is not working
char line[80];
printf("Enter sid to be deleted: ");
getline(line,sizeof(line));
sscanf(line,"%s",x.sid);
if (deleteStudents(x,students,courses) == 0)
printf("Student s has been deleted", x.sid);
else
printf("Student s does not exist", x.sid);
}
void printStudents(Snodeptr students) {
int count=0;
Snodeptr p=students;
char ch;
while((p->next)!=NULL){
printf("sid=%s,name=%s ",p->next->student.sid,p->next->student.sname);
p=p->next;
}
}