标题:字符串排序问题(帮找错!谢谢)
取消只看楼主
yingqiaji
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2018-4-15
结帖率:100%
已结贴  问题点数:10 回复次数:0 
字符串排序问题(帮找错!谢谢)
# include <stdio.h>
/*
2018年5月2日
对5个字符串排序
*/

int cmpd (char * x, char * y)

{
    int t;
    do
    {
        t = * x - * y;
        x++;
        y++;
    }while (* x == * y);
        if (t > 0)
            return 1;
        else
            return 0;
}

int main (void)

{
    char * a[] = {"aab","aba","boy","xigua","yang"};
    int m, n;
    char * p;
    for (m = 0; m < 4; m++)
    {
        for (n = 0; n < 4 - m; n++)
        {
            if (cmpd (a[n], a[n + 1]))
            {
                p = a[n];
                a[n] = a[n + 1];
                a[n + 1] = p;
            }
        }
    }
    for (p = a[0]; p <= a[4]; p++)
        printf ("%s\n", * p);
    return 0;
}
搜索更多相关主题的帖子: 字符串 排序 int char for 
2018-05-02 20:08



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-486572-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.034682 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved