Új hozzászólás Aktív témák

  • Jester01

    veterán

    válasz chabeee #2916 üzenetére

    Rengeteg módon. Például csinálsz egy struct-ot amiben benne van a magyar és az angol szó. Ezután qsort hívással, a megfelelő összehasonlító függvény megadásával, berendezed:

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

    struct entry
    {
    const char* eng;
    const char* hun;
    };

    static int compare_entries(const void* a, const void* b)
    {
    const struct entry* e1 = a;
    const struct entry* e2 = b;
    return strcmp(e1->eng, e2->eng);
    }

    int main()
    {
    struct entry words[] = {
    { "dog", "kutya" },
    { "donkey", "szamar" },
    { "content", "tartalom" },
    { "apple", "alma" },
    { "good", "jo" },
    { "diamond", "gyemant" }};
    const int count = sizeof words / sizeof words[0];
    int i;
    qsort(words, count, sizeof words[0], compare_entries);
    for(i = 0; i < count; ++i)
    {
    printf("%s %s\n", words[i].eng, words[i].hun);
    }
    return 0;
    }

    Jester

Új hozzászólás Aktív témák