#define _CRT_DISABLE_PERFCRIT_LOCKS
#define _CRT_SECURE_NO_WARNINGS

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

int main(int argc, char **argv)
{
    size_t n, m, i;
    char *s, *p, *field[64];
    char buf[32768];
    /* stdin und stout sind Funktionsaufrufe unter Win10 */
    FILE *in = stdin, *out = stdout;

    if (!freopen("list.txt", "rb", in)) return -1;
    if (!freopen("nodup.txt", "wb", out)) return -1;

    while (fgets(buf, sizeof(buf), in)) {

        for (field[i = 0] = p = buf; (p = strchr(p, ';')); p++) {
            if (i < sizeof(field)/sizeof(*field) - 1) {
                *p = 0;
                field[++i] = p + 1;
            }
        }

        for (n = 3; n < i - 1; n++) {
            if (field[n][0])
                for (m = n + 1; m < i; m++)
                    if (strcmp(field[n], field[m]) == 0)
                        field[m][0] = 0;
        }

        p = buf;

        for (n = 0; n < i; n++) {
            s = field[n];
#if 1
            while (*s)
                *p++ = *s++;
#else
            m = strlen(s);
            memcpy(p, s, m);
            p += m;
#endif
            *p++ = ';';
        }

        *p++ = '\n';
        *p = 0;

#ifdef _MSC_VER
        _fwrite_nolock(buf, 1, p - buf, out);
#else
        //fputs(buf, out);
        fwrite_unlocked(buf, 1, p - buf, out);
#endif

    }
    return 0;
}
