gpt4 book ai didi

c - C编程如何限制用户输入相同的用户名

转载 作者:行者123 更新时间:2023-11-30 16:44:28 25 4
gpt4 key购买 nike

我目前正在做客户忠诚度系统,需要注册用户名和密码。我需要限制用户输入相同的用户名,但我找不到任何信息。预先感谢您帮助我。

我将所有内容存储在文本文件中。

printf("\t\t\t\t\t   Enter Your Username: ");
scanf("%s", &Username);
printf("\t\t\t\t\t Enter Your Password: ");
scanf("%s", &Password);
//adding varable named NumofCust
NumOfCust++;
int i = 0;
//variable for boolean logic
int flag = 0;
int ch = 0;
int Points = 0;
for (i = 0; i <= NumOfCust; i++)
{
if (strcmp(user[i].Username, Username) == 0)
{
flag = 1;
break;
}
}

if (flag == 0)
{
strcpy(user[i].Username, Username);
strcpy(user[i].Password, Password);
};

//opening txt file read, append, and write
FILE *readfile = fopen("CustomerRegistration.txt", "r");
if (readfile)
{
FILE *CreateFile = fopen("CustomerRegistration.txt", "a");
fprintf(CreateFile, "%s\n%s\n%d\n", Username, Password, Points);
fclose(CreateFile);
printf("\t\t\t\t\tRegistration is Successful!!!\n\t\t\t\t\t");
}

else
{
FILE *CreateFile = fopen("CustomerRegistration.txt", "w");
fprintf(CreateFile, "%s\n%s\n%d\n", Username, Password, Points);
fclose(CreateFile);
printf("\t\t\t\t\tRegistration is Successful!!!\n\t\t\t\t\t");
}
system("pause");

最佳答案

您可以组织文本文件,因为每一行都是一个用户名,然后当用户注册帐户时解析该用户名的文本文件

bool isOriginalUsername(string name){
ifstream file;
file.open(//the file);
string line;
while(getline(file, line)
{
for(int i = 0; i > //number of users; i++)
{
if(name == line)
{
return false;
}
getline(file, line)
}
}
}

关于c - C编程如何限制用户输入相同的用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44478294/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com