I am trying to delete information from a linked list that i entered. I can get the infor into the linked list but i cannot delete it ---Any assistence or insight would be appreciated.
Code:
///TYPE.h///
#define MAXNUM 10
#define MAXNAME 30
typedef struct enode *Enodeptr;
typedef struct snode *Snodeptr;
typedef struct cnode *Cnodeptr;
struct studentType {
char sid[MAXNUM];
char sname[MAXNAME];
};
struct courseType {
char cno[MAXNUM];
char title[MAXNAME];
int hours;
};
struct snode {
struct studentType student; /*data stored in the node*/
Enodeptr firstE;
Snodeptr next,prior; /*pointer to the next node and previous */
};
struct cnode {
struct courseType course;
Enodeptr firstE;
Cnodeptr next,prior;
};
struct enode {
Enodeptr sNext, cNext;
Snodeptr sOwner;
Cnodeptr cOwner;
char grade;
};
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "types.h"
#include "students.h"
#include "enrolls.h"
Snodeptr sAlloc(void) { /*Working*/
/*Allocates storage for a snode and returns pointer to the structure */
return (Snodeptr) malloc(sizeof(struct snode));
}
void makenullStudents(Snodeptr *students) { /*Working*/
/*Creates an empty list of students and returns pointer to dummy node in the variable students */
(*students) = sAlloc();
}
int memberStudents(struct studentType x, Snodeptr students, Snodeptr *s) {
/*returns 0 if student structure x is present in students list
and 1 otherwise. It also returns a pointer (in s) to the snode where it
found x; If x is not found it should return a pointer to the snode
where x should be inserted */
Snodeptr p = students;
Snodeptr p1 = *s;
while(strcmp(p->next->student.sid, x.sid))
{
p = p->next;
}
return 0;
}
int insertStudents(struct studentType x, Snodeptr students) { /*Working*/
/*inserts the student structure x in the student list; returns 0
if successful and 1 if failed */
Snodeptr p = students;
while(p->next != NULL)
{
p = p->next;
}
Snodeptr new = malloc(sizeof(struct snode));
new->student = x;
p->next = new;
new->prior = p;
new->next = NULL;
return 0;
}
int deleteStudents(struct studentType x, Snodeptr students, Cnodeptr courses) { /*Working*/
/* deletes the student structure x in the student list; returns 0
if successful and 1 if failed */
Snodeptr p = students;
Snodeptr p1;
while(strcmp(p->next->student.sid, x.sid))
{
p = p->next;
}
p1 = p->next;
p->next = p->next->next;
p->next->prior = p;
return 0;
}
void printStudents(Snodeptr students) { /*Working*/
/* prints the list of students (sid and names) in pretty format with
-more- like option */
int count = 0;
Snodeptr p = students;
char ch;
while((p->next)!=NULL)
{
printf("sid = %s, name = %s \n", p->next->student.sid, p->next->student.sname);
p = p->next;
}
}