【发布时间】:2013-04-15 01:18:09
【问题描述】:
这是我得到分段错误的函数
void searchcity()
{
struct city *ptr=citylist;
printf("Which city would you like me to search?: ");
scanf("%s",searchedcity);
// printf("%s",searchedcity);
while(ptr)
{
if(!strcmp(searchedcity,ptr->name))
printf("name= %s, statecode = %s,population = %s,region = %s,zipcode = %s\n",ptr->name,ptr->statecode,ptr->population,ptr->region,ptr->zipcode);
else
printf("sorry, couldnt find that city");
ptr=ptr->next;
}
}
不确定是什么原因造成的。
【问题讨论】:
-
可能有很多原因,但没有更多代码就很难说出来
-
这里没有足够的代码来调试这个。
-
在函数中是否有任何原因导致它?
-
@alex 我们需要查看更多代码才能弄清楚这一点,而无需猜测。
-
你有没有用调试器检查过这个问题,看看是否有任何指针是
NULL,但不应该是?
标签: c function segmentation-fault strcmp