指向指针的指针
在一组已经进行升序排列的字符穿中,用折半查找法找出第一个字符相同的字符串,并输出.main()
{
void strsa(char **,int);
char *arr[5]={"abc","acd","afc","bcd","bd"};
strsa(arr,5);
}
void strsa(char **array,int a)
{
int i,bot,top,j,k;
for (i=0;i<a;i++)
{
bot=i;
top=a-1;
while (top>bot)
{
j=(top+bot)/2;
if (*(array[i]+0)==*(array[top]+0))
{
k=top;
for(;k>bot;k--)
printf("The first letter of string %d as same as string %d", top,i);
bot=j;
}
else
top=j;
}
}
}
运行时怎么会是死循环呢?
搜索更多相关的解决方案:
指针
----------------解决方案--------------------------------------------------------
这个程序输出的是字符串序号,而不是字符串
----------------解决方案--------------------------------------------------------
main() { void strsa(char **,int); char *arr[5]={"abc","acd","afc","bcd","bd"}; clrscr(); strsa(arr,5); } void strsa(char **array,int a) { int i,bot,top,j,k; for (i=0;i<a;i++) { bot=i; top=a-1; while (top>bot) { j=(top+bot)/2; if (*(array[bot]+0)==*(array[top]+0)) { printf("The first letter of string %d as same as string %d\n", top,bot); bot+=1; } else top=j;
} } getch(); } 还有鞋问题,但勉强通过了,自己再研究研究吧
----------------解决方案--------------------------------------------------------