-1

这是一个名为 sort_list_forward 的小函数

struct customer * sort_list_forward (struct customer * liste_)
{
    struct customer *pointer1, *pointer2;
    struct customer tmp;

    if (liste_!=NULL)
    {
        pointer1 = liste_;
        while(pointer1 != NULL)
        {
            pointer2 = pointer1->next;
            while(pointer2 != NULL)
            {

                if (strcmp(pointer1->name,pointer2->name) > 0)
                {
                    strcpy(tmp.name, pointer2->name);
                    strcpy(pointer2->name, pointer1->name);
                    strcpy(pointer1->name, tmp.name);
                }
                pointer2 = pointer2->next;
            }
            pointer1 = pointer1->next;
        }
        return liste_;
    }
    else
    {
        printf("sortnames: no elements avaiable");
        return NULL;
    }
}

结构客户看起来像

typedef struct customer {
    char name[256];
    struct customer *next;
    struct customer *previous;
};

如果我使用这个函数,输出看起来像

Ann
Bernd
Hans
barbara
bart
berta
homer

但我想要一个看起来像的输出

Ann
barbara
bart
berta
Bernd
homer
Hans

a A b B c C d D ...

我搜索了8个多小时,但一无所获:(

4

2 回答 2

3

而不是strcmp,使用排序规则比较您的字符串,方法是调用strcoll.

于 2013-03-30T16:22:20.323 回答
1

用作strcasecmp排序顺序是忽略单词的大小写。

于 2013-03-30T16:24:38.307 回答