How to delete specific records in C

Asked by At

I have a simple register that requires the user to input a person's first name, last name, age, address and nickname. The assignment is to delete a users record with one option and to delete a single line in another. I'm not sure how to go about the delete.

I have created the general program and I know that it requires an IF statement for the two options but I'm not certain how to go about it.

#include <stdio.h>

int main(){
    int option;

      printf("[1] To create a new student onto the register\n");
      printf("[2] To delete a record in the register\n");
      printf("[3] To delete a line in the register\n");
      printf("Option: ");

      if (option==1){
      if (option==2){

      if (option==3){

      return 0;

void Register(){

    char Name[100],Address[100],Lname[100],Nickname[100];
    int Age=0,Phoneno=0;

    fptr = fopen("Register.txt", "a+");

    if(fptr == NULL)
        printf("Error! There is no file to write to. Please Create a file");


    printf("Enter the first name of a person: ");

    printf("Last Name of %s: ",Name);

    printf("What is the age of %s: ",Name);
    scanf("%d", &Age);

    printf("What is the address of %s: ",Name);

    printf("Does %s have a nickname?");

    printf("This ends the entry of info into the file\n");

    fprintf(fptr,"First name: %s\n",Name);
    fprintf(fptr,"Last name: %s\n"Lname);
    fprintf(fptr,"Age: %d\n",Age);
    fprintf(fptr,"Address: %s\n",Address);
  • If you choose option 1, the program creates a record of a student.
  • If you choose option 2, the program should delete all information about a person if you enter their first name.
  • If you choose option 3, the program asks for the students first name then asks which option to delete.

An example for option 3 is

First name: Michael
Last name:
Address: 17 Habour street
Nickname: Mike

where his last name was erased

0 Answers