Skip to content
Snippets Groups Projects
Commit 1cb6a94b authored by Mattias Erlingsson's avatar Mattias Erlingsson
Browse files

changed for-loop implementation

parent 387a9af7
No related branches found
No related tags found
No related merge requests found
list.c 100644 → 100755
File mode changed from 100644 to 100755
......@@ -37,15 +37,18 @@ void delete (struct list *student_list) {
scanf("%s", &array);
struct list_elem *e;
for (e = list_begin(student_list); e != list_end(student_list); e = list_next(e)){
for (e = list_begin(student_list); e != list_end(student_list);) {
struct student *s = list_entry(e, struct student, elem);
/*if the two arrays are equal we delete it and free memory*/
if(strcmp(array, s->name)==0){
struct list_elem* temp = e;
list_remove(e);
if (strcmp(array, s->name) == 0) {
struct list_elem *temp = e;
e = list_next(e);
list_remove(temp);
free(s->name);
free(s);
break;
}
e = list_next(e);
}
}
......@@ -70,6 +73,7 @@ void quit (struct list *student_list) {
free(s->name);
free(s);
}
exit(0);
}
int main() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment