关于strcmp函数的使用?

勤奋的下里巴人 2014-11-23 09:32:35
我要对strings字符串数组进行按升序排序。采用了 (strcmp(strings[top],strings[seek])函数,一直闹不明白的是strcmp(strings[top],strings[seek])> 0,而不是strcmp(strings[top],strings[seek]) < 0?
strcmp(strings[top],strings[seek]) 函数不是说strings[top]排在strings[seek],就返回大于0吗?那为什么还需要下面答案中提供的进行呼唤??

答案:
void stsrt(char *strings[], int num)
{
char *temp;
int top, seek;

for (top = 0; top < num-1; top++)
for (seek = top + 1; seek < num; seek++)
if (strcmp(strings[top],strings[seek]) >0)
{
temp = strings[top];
strings[top] = strings[seek];
strings[seek] = temp;
}
}
...全文
58 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧