我正在为一个用于帐户交易的项目编写代码。但是,我的支票帐户ID流程存在一些小问题。我使用的结构函数属于字符串数组,它可以帮助我稍后轻松地解决子任务,这是因为我尝试使用字符串比较来检查account_ID。输出无法显示我的期望。我不知道如何扫描数组中的变量以检查File-text中的字符串数组结构。
我竭尽所能扫描变量。但这是行不通的。这是我的代码。
struct customers{
char phone[13];
char id[9];
char name[31];
char address[201];
char city[31];
char date[11];}customer
int main()
{
FIle *fc
if((fc=fopen("clients.txt","a+"))=NULL)
printf("Can not open");
else
{
int i = 0, a = 0;
fflush(stdin);
customer_ID:
printf("Enter the ID (maximum 8 digits): ";
gets(customer[i].id);
if (strlen(customer[i].id)!=8)
{
printf("Wrong the number of digits ! Enter Again!\n");
goto customer_ID;
}
while(fscanf(fc,"%s\n%[^\n]%*c%s\n%[^\n]%*c%[^\n]%*c%s\n\n",customer[a].id,customer[a].name,customer[a].phone,customer[a].address,customer[a].city,customer[a].date)!=EOF)
{
if (strcmp(customer[i].id,customer[a].id)==0)
{
printf("Account ID has been already used ! Please Enter other ID !\n");
goto customer_ID;
}
}
输出: * 实际结果: 它不会显示“帐户ID已被使用!请输入其他ID!”
* Expected Result:
Print "Account ID has been already used ! Please Enter other ID !"
答案 0 :(得分:0)
如果ID始终具有相同的大小,则可以尝试使用strstr,以使其成为
if (strstr(customer[i].id,customer[a].id))
以这种方式,您的持久代码空间