C语言订单系统客户隐私安全的个人信息更新功能开发求助
订单系统客户信息更新功能隐私问题解决需求
我正在开发一款简易订单系统,需要实现客户个人信息更新功能。目前我的代码会打印整个客户信息文本文件(custdeet.txt),让用户选择要更新的行,这会导致客户能查看其他用户的隐私信息,我无法解决这一问题。
注:我曾用类似方式实现菜单菜品更新功能且运行正常,但作为编程新手,我找不到更好的改进方案。以下是当前陷入瓶颈的函数代码:
void ChgDeet() { FILE *cd1; FILE *cd2; int line = 0; int temp = 1; int flag = 0; char fname[50]; char lname[50]; char email[250]; int number; char d; printf("\nNAME\t\tEMAIL\t\t\tPHONE NUMBER\n"); cd1 = fopen("custdeet.txt", "r"); // open file in read mode if (cd1 == NULL){ printf("\nUnable to open file.\n"); quit(); } while (!feof(cd1)){ d = getc(cd1); printf("%c",d); } //take cd1 to start point rewind(cd1); printf("\n\nEnter line number to be updated: "); scanf("%d", &line); fflush(stdout); //open duplicated file in write mode cd2 = fopen("copy.txt", "w"); while (!feof(cd1)){ d = getc(cd1); if (d == '\n') temp++; //until the line to be deleted comes, copy content from one file to the other if (temp != line){ putc(d, cd2); } if (flag == 0 && temp == line){ printf("\nUpdated First Name: "); scanf("%s",&fname); printf("Updated Last Name: "); scanf("%s",&lname); printf("Updated Email: "); scanf("%s",&email); printf ("Updated Phone Number (+60): "); scanf("%d",&number); fprintf(cd2, "\n%s\t%s\t%s\t+60%d", fname,lname,email,number); flag = 1; } } fclose(cd1); fclose(cd2); remove("custdeet.txt"); rename("copy.txt","custdeet.txt"); printf("\nUpdate Menu: \n"); cd1 = fopen("custdeet.txt", "r"); if (cd1 == NULL){ printf("\n Unable to open file.\n"); quit(); } while (!feof(cd1)) { d = getc(cd1); printf("%c", d); } fclose(cd1); printf("\nYour personal information updated!"); printf("\n...redirecting you back to homepage..."); CustMenu(); }
内容的提问来源于stack exchange,提问作者Kemmy
相关产品推荐
相关产品推荐

