我有一个简单的寄存器,要求用户输入一个人的名字,姓氏,年龄,地址和昵称。分配是使用一个选项删除用户记录,而在另一个选项中删除一行。我不确定如何进行删除。
我已经创建了通用程序,我知道这两个选项都需要使用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
他的姓氏被删除的地方