当前位置: 代码迷 >> C语言 >> [求助]那里有问题?
  详细解决方案

[求助]那里有问题?

热度:115   发布时间:2006-04-29 14:47:00.0
[求助]那里有问题?
#include "stdio.h"
void choicesort(char **p1,int num)
{char **p2,**temp,**temp2;
for(;p1<p1+num-1;p1++)
{ temp=p1;
for(p2=p1+1;p2<p1+num;p2++)
if(**temp>**p2)temp=p2;
**temp2=**p1;
**p1=**temp;
**temp=**temp2;
}
}
main(){int i;
char *list[]={"boy",
"girl",
"hacker",
"cracker","honker","xbox","blogger","vfp","qiaomu","pragrammer"};
choicesort(list,10);
for(i=0;i<10;i++)
printf("%s",list[i]);
getch();
}//这是一个用指针数组和指向指针的指针的实现的对10个字符串排序,怎么在运行的时候没有结果呢?谢谢
搜索更多相关的解决方案: include  hacker  

----------------解决方案--------------------------------------------------------

指针乱用,字符串大小不是那么比较的

建议打入死牢~ 回去好好看书


----------------解决方案--------------------------------------------------------
这个也太乱了吧,!
----------------解决方案--------------------------------------------------------
请指点
----------------解决方案--------------------------------------------------------
没关系的.错了自己慢慢先看书琢磨,真不懂再问.
----------------解决方案--------------------------------------------------------

楼主,我如果找你程序的错误,至少能找出10处,怕你生气,我就不找了,看样子指针你还不懂,我下面给你写了个数组的,看看吧

#include <stdio.h>
#include <conio.h>
#include <string.h>

const int SIZE = 10;

int main(void)
{
void Sort(char stra[][SIZE]);

char stra[SIZE][SIZE] = {"fan", "song", "zhang", "zhao", "wang",
"li", "yin", "shu", "tian", "wei"};
int ia, ipass;

Sort(stra);

for (ia = 0; ia < SIZE; ia++)
{
printf("%s\n", stra[ia]);
}

getch();
return 0;
}

void Sort(char stra[][SIZE])
{
int ib, ipass;
char strb[10];

for (ipass = 1; ipass < SIZE; ipass++)
{
for (ib = 0; ib < SIZE - 1; ib++)
{
if (strcmp(stra[ib], stra[ib + 1]) > 0)
{
strcpy(strb, stra[ib]);
strcpy(stra[ib], stra[ib + 1]);
strcpy(stra[ib + 1], strb);
}
}
}
}












----------------解决方案--------------------------------------------------------

#include <stdio.h>
#include <conio.h>
#include <string.h>

const int SIZE = 10;

int main(void)
{
void Sort(char *stra[]);

char *stra[SIZE] = {"fan", "song", "zhang", "zhao", "wang",
"li", "yin", "shu", "tian", "wei"};
int ia, ipass;

Sort(stra);

for (ia = 0; ia < SIZE; ia++)
{
printf("%s\n", stra[ia]);
}

getch();
return 0;
}

void Sort(char *stra[])
{
int ib, ipass;
char *strb;

for (ipass = 1; ipass < SIZE; ipass++)
{
for (ib = 0; ib < SIZE - 1; ib++)
{
if (strcmp(*(stra + ib), *(stra + ib + 1)) > 0)
{
strb = *(stra + ib);
*(stra + ib) = *(stra + ib + 1);
*(stra + ib + 1) = strb;
}
}
}
}












----------------解决方案--------------------------------------------------------
  相关解决方案