int main (void){
do
{
mainmenu:
mainmenu();
switch(option)
{
//add new contact
case 1:addcontact(storage);savecontact(storage);
break;
case 2:searchcontact();
break;
}
}while(true);
}
void searchcontact()
{
char searchname[20];
system("cls");
do
{
int find = 0;
printf("Contact Search\n Name of the Contact:\n");
fflush(stdin);
scanf("%[^\n]",&searchname);
length=strlen(searchname);
f=fopen("contact.txt","rb");
system("cls");
printf("Search the result for %s\n",searchname);
while(fread(&storage,sizeof(storage),space,f)==true)
{
for(i=0;i<=length;i++)
storage[space].name[i]=storage[space].name[i];
storage[space].name[length]='\0';
if(stricmp(storage[space].name,searchname)==false)
printf("Name\t:%s\nPhone\t:%d\nE-mail\t:%s\n",storage[space].name,storage[space].hpnum,storage[space].email);
find++;
}
if(find==false)
printf("\nNo match found!");
else
printf("\n %d match(s) found",find);
fclose(f);
printf("\nTry again?\t[1] Yes\t[2] No\n");
scanf("%d",&choice);
}while(choice==true);
}
我在搜索时遇到问题...添加联系人后,我无法再次搜索...我使用 stricmp 搜索联系人...同时我输入了我为保存联系人而输入的正确名称,它仍然无法搜索...继续打电话给我再试一次。因此,该错误主要存在于那里的搜索功能上。我的真值是==1,我的假值是==0。