0
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搜索联系人...尽管我发现了保存联系人的正确名称,但它仍然无法搜索出来......继续打电话给我再试一次。所以这个bug主要是在那里的搜索功能。我的真实值是== 1,而我的错误值是== 0。与联系人系统管理的搜索功能问题
是C代码吗?一些功能和变量定义缺失,如选项存储选择...你可以给缺少的部分? – 2013-03-02 09:02:19
@nullix这没关系......我试图将我的代码上传到其他地方,你可以下载它... =) 由于在这里不能写太多的编码,我宁愿你下载我的文件,并理解我的整个编码以便让您解决我的问题。 =) http://www.mediafire.com/?pkqsasr8forgjwv – jefferyleo 2013-03-02 12:21:53
我把它移植到linux来测试它,并修复你的功能,看到答案。 – 2013-03-03 21:18:52