我正在为帐户交易编写一个项目。但是,在我的支票账户ID过程中有一些小问题。我使用了结构函数属于字符串数组,这可以帮助我以后轻松解决我的子任务,重点是当我尝试使用字符串比较来检查account_ID时。输出无法显示我的期望。我不知道如何扫描数组中的变量以检查文件文本中的字符串数组结构。
我努力通过很多方式扫描变量。但它不起作用。这是我的代码。
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,"%sn%[^n]%*c%sn%[^n]%*c%[^n]%*c%snn",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 已被使用!请输入其他身份证件!
* Expected Result:
Print "Account ID has been already used ! Please Enter other ID !"
也许尝试使用 strstr,以防 id 始终处于相同的大小,以便它将
if (strstr(customer[i].id,customer[a].id))
这样你的持久代码空间