sentinel list在读取时总是给出相同的输出,为什么? C

时间:2017-11-26 16:21:33

标签: c

sentinel list在读取时总是给出相同的输出,为什么? 请耐心等待,我不知道出了什么问题。

这是我的代码:

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

/*----------------------------------------------------------Strukturak------------------*/
typedef struct tempfile
{
    int ev;
    int hnap;
    int nap;
    int ora;
    int perc;
    int meret;
    char nev[218];
    char kiterjesztes[218];
}tempfile;
typedef struct tmplist
{
    tempfile fadat;
    struct tmplist *kov;
} templist;
/*----------------------------------------------------------Strukturak------------------*/
/*----------------------------------------------------------Listamuveletek--------------*/


templist* wardedtemplist(void)
{
    templist *ward1;
    templist *ward2;
    ward1 = (templist*)malloc(1 * sizeof(templist));
    ward2 = (templist*)malloc(1 * sizeof(templist));
    ward1->kov = ward2;
    ward2->kov = NULL;
    return ward1;
}
templist* ujtemplistelem(tempfile adat)
{
    templist *ujtemplistelem;
    ujtemplistelem = (templist*)malloc(1 * sizeof(templist));
    if (ujtemplistelem != NULL)
    {
        ujtemplistelem->fadat = adat;
        ujtemplistelem->kov = NULL;
    }
    return ujtemplistelem;
}
templist* beszurastemplist(templist* ujtemplistelem, templist* ward1)
{

    templist* wifi;
    wifi = (templist*)malloc(1 * sizeof(templist));
    wifi->kov = ward1->kov;
    ward1->kov = ujtemplistelem;
    ujtemplistelem->kov = wifi->kov;
    free(wifi);

    return ward1;
}

/*----------------------------------------------------------Listamuveletek--------------*/
/*---------------------------------dir txt file beolvasasa (huh boi ez nehez volt)------*/

int main(void)
{
    char input[1024];
    char edited[1024];
    int i = 0;
    int p = 0;
    FILE *temp;
    tempfile a;
    templist* ujlea;
    templist* dirlist;
    templist*aktualiselem;
    dirlist = wardedtemplist();

    system("dir>temp.txt");
    temp = fopen("temp.txt", "r");
    if (temp == NULL)
        return -1;

    while (fgets(input, sizeof input, temp))
    {
        if (input[0] == ' ' || input[0] == '\n')
        {
            continue;//atugorja azokat a sorokat amik space vagy ujsorral kezdodnek
        }
        if (strstr(input, "<DIR>"))
        {
            continue;//atugorja azokat a sorokat okat amikben benne van a <DIR>
        }
        while (input[i] != '\0')
        {
            if (input[i] != '˙')
            {
                edited[p] = input[i];
                p++;
            }
            i++;
        }
        edited[p] = '\0';                        //rongyá editelése a sornak
        p = 0;
        i = 0;
        while (edited[i] != '\0')
        {
            if (edited[i] == '.')
                edited[i] = ' ';
            i++;
        }
        i = 0;


        sscanf(edited, "%d  %d  %d   %d:%d    %d %s %s\n", &a.ev, &a.hnap, &a.nap, &a.ora, &a.perc, &a.meret, &a.nev, &a.kiterjesztes);
        printf("%d.%d.%d. %d:%d  niz  %d byte   %s.%s\n", a.ev, a.hnap, a.nap, a.ora, a.perc, a.meret, a.nev, a.kiterjesztes);
        ujlea = ujtemplistelem(a);
        dirlist = beszurastemplist(ujlea, dirlist);
    }

    fclose(temp);
    system("DEL temp.txt");




    aktualiselem = dirlist->kov; //Első kihagy
    while (aktualiselem->kov != NULL) // Ucso kihagy
    {
        printf("%d.%d.%d. %d:%d    %d byte   %s.%s\n", a.ev, a.hnap, a.nap, a.ora, a.perc, a.meret, a.nev, a.kiterjesztes);
        printf("==========\n\n");
        aktualiselem = aktualiselem->kov;
    }



    printf("press enter\n");
    getchar();
    return 0;
}


/*---------------------------------dir txt file beolvasasa (huh boi ez nehez volt)------*/

第一个printf打印将进入列表的数据,第二个printf打印sentinel列表数据。

第一个顺利,做它需要做的事情, 但是第二种方法是只打印一个元素,就像许多数据一样多。

是什么导致这种情况?

0 个答案:

没有答案