首页 > 解决方案 > 如何删除C中的特定记录

问题描述

我有一个简单的寄存器,要求用户输入一个人的名字、姓氏、年龄、地址和昵称。分配是用一个选项删除用户记录,并在另一个选项中删除一行。我不确定如何进行删除。

我已经创建了通用程序,并且我知道这两个选项需要一个 IF 语句,但我不确定如何去做。

#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: ");
      scanf("%d",option);

      if (option==1){
        Register();
      }
      if (option==2){

      }
      if (option==3){

      }
      return 0;
  }

void Register(){

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

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

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

    fflush(stdin);

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

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

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

    fflush(stdin);
    printf("What is the address of %s: ",Name);
    gets(Address);

    printf("Does %s have a nickname?");
    gets(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);
    fprintf(fptr,"Nickname:%s\n\n",Nickname);
    fclose(fptr);
}

选项 3 的示例是

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

他的姓氏被抹去的地方

标签: c

解决方案


推荐阅读