BlueBear icon

xkostrej.c

BlueBear | PRO | 05/05/14 04:28:06 PM UTC | 0 ⭐ | 536 👁️ | Never ⏰ | []
C |

4.21 KB

|

None

|

0 👍

/

0 👎

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
typedef struct zamestnanec
{
    char meno[31];
    char priezvisko[31];
    int typ;
    float mzda;
    char datum[10];
    struct zamestnanec *next;
}zam_t;
 
zam_t *nacitaj()
{
    FILE *fp = fopen("zamestnanci.txt", "r");
    int pocet = 0;
    zam_t *first = NULL;
    zam_t *actual = NULL;
    char placeholder;
    if(fp == NULL)
    {
        printf("Zaznamy neboli nacitane\n");
        return NULL;
    }
    else
    {
        first = (zam_t *)malloc(sizeof(zam_t));
        fscanf(fp, "%s\n", first->meno);
        fscanf(fp, "%s\n", first->priezvisko);
        fscanf(fp, "%d\n", &first->typ);
        fscanf(fp, "%f\n", &first->mzda);
        fscanf(fp, "%s\n", first->datum);
        fscanf(fp, "%c\n", &placeholder);
 
        first->next = (zam_t *)malloc(sizeof(zam_t));
        actual = first->next;
 
        pocet++;
 
        while(!feof(fp))
        {
            fscanf(fp, "%s\n", actual->meno);
            fscanf(fp, "%s\n", actual->priezvisko);
            fscanf(fp, "%d\n", &actual->typ);
            fscanf(fp, "%f\n", &actual->mzda);
            fscanf(fp, "%s\n", actual->datum);
            fscanf(fp, "%c\n", &placeholder);
            if(!feof(fp))
            {
                actual->next = (zam_t *)malloc(sizeof(zam_t));
                actual = actual->next;
            }
            pocet++;
        }
        actual->next = NULL;
 
        printf("Nacitalo sa %d zaznamov\n", pocet);
    }
 
    return first;
}
 
int vypis(zam_t *record)
{
    zam_t *actual = record;
    int pocet = 1;
    while(actual != NULL)
    {
        printf("%d.\n", pocet);
        printf("%s\n", actual->meno);
        printf("%s\n", actual->priezvisko);
        if(actual->typ == 1)
        {
            printf("Riadiaci pracovnik\n");
        }
        else if(actual->typ == 0)
        {
            printf("Bezny zamestnanec\n");
        }
        printf("%.2f\n", actual->mzda);
        printf("%s\n", actual->datum);
        pocet++;
        actual = actual->next;
    }
}
 
void pridaj(zam_t **zoznam)
{
    int pozicia, i;
    zam_t *novy_zaznam = (zam_t*)malloc(sizeof(zam_t));
    zam_t *actual;
 
    scanf("%d\n", &pozicia);
    scanf(" %s", novy_zaznam->meno);
    scanf(" %s", novy_zaznam->priezvisko);
    scanf(" %d", &novy_zaznam->typ);
    scanf(" %f", &novy_zaznam->mzda);
    scanf(" %s", novy_zaznam->datum);
 
    if (*zoznam == NULL) // zoznam je prazdny, pridaj na 1. miesto
    {
        *zoznam = novy_zaznam;
        return;
    }
 
    actual = *zoznam; // zaznam_pred najprv bude 1. zaznam v zozname
 
    for (i = 1; i < pozicia - 1; i++)
    {
        if (actual->next == NULL) 
        {
            break;
        }
        actual = actual->next;
    }
 
    if (pozicia == 1)
    {
        novy_zaznam->next = *zoznam;
        *zoznam = novy_zaznam;
    }
    else
    {
        novy_zaznam->next = actual->next; // ten prvok, co nasledoval za nim bude nasledujuci prvok nasho noveho prvku
        actual->next = novy_zaznam; // nasledujuci prvok bude nas novy zaznam
    }
 
    return;
}
 
zam_t *zmaz(zam_t *start)
{
    zam_t *ptr1, *ptr2, *dup;
    ptr1 = start;
 
    /* Pick elements one by one */
    while(ptr1 != NULL && ptr1->next != NULL)
    {
        ptr2 = ptr1;
 
        /* Compare the picked element with rest of the elements */
        while(ptr2->next != NULL)
        {
            /* If duplicate then delete it */
            if(strcmp(ptr1->meno, ptr2->next->meno) == 0)
            {
                if(strcmp(ptr1->priezvisko, ptr2->next->priezvisko) == 0)
                {
                    dup = ptr2->next;
                    ptr2->next = ptr2->next->next;
                    free(dup);
                }
            }
            else /* This is tricky */
            {
                ptr2 = ptr2->next;
            }
        }
        ptr1 = ptr1->next;
    }
    return start;
}
 
zam_t *aktualizuj(float mzda, zam_t *record)
{
    zam_t *first = record;
    zam_t *actual = first;
    int pocet = 0;
    while(actual != NULL)
    {
        if(mzda < actual->mzda)
        {
            actual->mzda = mzda;
            pocet++;
        }
        actual = actual->next;
    }
    printf("Aktualizovalo sa %d zaznamov\n", pocet);
    return first;
}
 
int main()
{
    char vyber[10];
    zam_t *zamestnanci = NULL;
    float pos;
    while(1)
    {
        scanf(" %s", &vyber);
        if(strcmp(vyber, "koniec") == 0)
        {
            return 0;
        }
        else if(strcmp(vyber, "nacitaj") == 0)
        {
            zamestnanci = nacitaj();
        }
        else if(strcmp(vyber, "vypis") == 0)
        {
            vypis(zamestnanci);
        }
        else if(strcmp(vyber, "pridaj") == 0)
        {
            pridaj(&zamestnanci);
        }
        else if(strcmp(vyber, "zmaz") == 0)
        {
            zamestnanci = zmaz(zamestnanci);
        }
        else if(strcmp(vyber, "aktualizuj") == 0)
        {
            scanf("%f", &pos);
            zamestnanci = aktualizuj(pos, zamestnanci);
        }
    }
    return 0;
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  • Syutrsz icon
    03/31/26 10:20:33 PM UTC
    text |

    0 B

    |

    0 👍

    /

    0 👎

    Best t33n active cpx link daily updates!
     Copy and paste the link in a new browser tab and then hit enter!
     https://crazyporn.@xxx/members/157354/?asgtbndr=1&play=true&spon=adworld&zone=400
     Remove the @ 
  • Zyubi icon
    04/05/26 02:25:34 AM UTC
    text |

    0 B

    |

    0 👍

    /

    0 👎

    Best t33n active cpx link daily updates!
     Copy and paste the link in a new browser tab and then hit enter!
     https://crazyporn.xxx/members/157354/?asgtbndr=1&play=true&spon=adworld&zone=400