这里有些疑惑 不是很清楚这段代码的作用
//第一段
bool finduserinfo(char *account,char *pwd)
{
for(int i=0;i<nCustomer;i++)
{
if(strcmp(account,customer[i].account) == 0 && strcmp(pwd,customer[i].pwd) == 0)
return true;
}
return false;
}
//第二段
Customer *findcustomer(char account[20])
{
for(int i=0;i<nCustomer;i++)
{
if(strcmp(account,customer[i].account) == 0)
return customer+i;
}
return NULL;
}
第一段代码,是查找比对用户的信息,形参传入两段字符串,账户和密码,如果账户和密码都正确且都已存在就返回 1 ,否则返回 0.
第二段代码,形参传入账户字符串,在结构体数组 customer[].account 查找,找到就返回所处的数组地址位置,没找到就返回空 NULL。
strcmp 这个函数用于比较2个字符串是否相等。&& 代表与运算。通俗点讲就是2个判断都满足,就返回true,否则返回false
第二段同理。
第二个函数是做判断customer有多少个和account相同的数量