Note that there are some explanatory texts on larger screens.

plurals
  1. POProgram gets hung up when I use "delete" function
    text
    copied!<p>I'm trying to write a program where it'll take in info from a user, and the user will have options on what to do. The options are to add, modify, delete, display certain info, find the average, and exit. I have written code for all of them but I can't get my delete function to work. Here is my code:</p> <pre><code>void delete_student(struct students *list, int *count) //Delete's Selected student { int id4; int k; if (*count != 0) { printf("\nEnter the ID of the student you wish to delete: "); scanf("%d\n", &amp;id4); for (int i = 0; i &lt; *count; i++) //Searches for the selected student { k = i; if (list[i].id == id4) { printf("\nStudent found.\nDeleting...\n"); for (int c = k; c &lt; *count; c++) //Deletes the student if found { list[c].id = list[c + 1].id; strcpy(list[c].name, list[c + 1].name); list[c].age = list[c + 1].age; strcpy(list[c].dept, list[c + 1].dept); list[c].grade = list[c + 1].grade; } *count = *count - 1; printf("\nDeletion Complete.\n"); break; } else printf("\nStudent not found. Please try again.\n"); break; } } else printf("\nNo student's to delete.\n"); } </code></pre> <p>Edit: When I go through the program, and I select to use this function, it'll ask me for the "ID" and then it does nothing and has a blinking cursor.</p> <p>Could someone tell me what I'm doing wrong? There's more code if you need it.</p> <p>Is this how the last element would be deleted:</p> <pre><code>list[*count].id = 0; strcpy(list[*count].name, NULL); list[*count].age = 0; strcpy(list[*count].dept, NULL); list[*count].grade = 0; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload