c - 如何删除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);
}
- 如果您选择选项 1,程序会创建学生记录。
- 如果您选择选项 2,如果您输入一个人的名字,程序应删除有关该人的所有信息。
- 如果您选择选项 3,程序会询问学生的名字,然后询问要删除哪个选项。
选项 3 的示例是
First name: Michael
Last name:
Age:16
Address: 17 Habour street
Nickname: Mike
他的姓氏被抹去的地方
解决方案
推荐阅读
- javascript - 在 createContext 和 Provider 组件上两次为反应上下文提供值
- html - 当连接打开和关闭标签的活动/突出显示时,有什么方法可以改变垂直线的颜色?
- umbraco - 另一个宏中的宏
- python - 从数组列表对象中删除值的类函数
- keras - ValueError 层序贯_13的输入0与层不兼容:预期ndim = 3,发现ndim = 4接收到完整形状:(无,无,无,无)
- node.js - 承诺和异步
- android-studio - 教程与我用北极狐实际创建的内容不匹配
- kubernetes - Envoy 访问日志字段主机
- r - 使用 R 循环查找概率
- reactjs - 我如何编写一个反应钩子来获取 2 个数据请求