【发布时间】:2013-03-02 07:22:33
【问题描述】:
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。
【问题讨论】:
-
是C代码吗?缺少某些函数和变量定义,例如选项存储选择...您能提供缺少的部分吗?
-
@nullix 没关系...我正在尝试将我的编码上传到其他地方,你可以下载它...=)由于这里不能写太多编码,我宁愿你下载我的文件并了解我的整个编码,以便让您解决我的问题。 =) mediafire.com/?pkqsasr8forgjwv
-
我将它移植到 linux 上进行测试,并修复了您的功能,请参阅答案。
-
连接一次、创建个人资料然后再也不阅读是非常不友好的。回答人们花了几个小时阅读您的精彩代码。我回答了。
标签: string function search compare