Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- struct Zoznam
- {
- char meno[31];
- char priezvisko[31];
- long long rodnecislo;
- float mzda;
- struct Zoznam* next;
- } Zoznam;
- void nacitaj(struct Zoznam **head) //fully working
- {
- printf("%p\n",head);
- FILE *fr;
- fr = fopen("zamestnanci.txt","r");
- if(fr!=NULL)
- {
- int pocet=0;
- while(1)
- {
- long long rc=0;
- float plat=0;
- struct Zoznam* temp= (struct Zoznam*) malloc(sizeof(struct Zoznam));
- temp->next=NULL;
- if(fscanf(fr,"%s %s %lld %f",temp->meno,temp->priezvisko,&rc,&plat)==EOF)
- {
- break;
- }
- temp->rodnecislo = rc;
- temp->mzda = plat;
- if(*head==NULL)
- {
- *head = temp;
- }
- else
- {
- struct Zoznam* end;
- end = *head;
- while(end->next!=NULL)
- {
- end = end->next;
- }
- end->next=temp;
- }
- pocet++;
- }
- printf("Nacitalo sa %d zaznamov\n",pocet);
- }
- }
- void vypis(struct Zoznam** head) //fully working
- {
- printf("%p\n",head);
- struct Zoznam *temp=*head;
- int pos = 1;
- while(temp!=NULL)
- {
- printf("%d. %s %s %lld %.2f\n",pos,temp->meno,temp->priezvisko,temp->rodnecislo,temp->mzda);
- pos++;
- temp=temp->next;
- }
- printf("\n");
- }
- void pridanie(struct Zoznam** head) //fully working
- {
- struct Zoznam* new_temp= (struct Zoznam*) malloc(sizeof(struct Zoznam));
- struct Zoznam* old_temp= *head;
- new_temp->next = NULL;
- int n;
- printf("Zadaj cislo pozicie\n");
- scanf("%d",&n);
- printf("Zadaj meno \n");
- long long rc = 0;
- float mzda = 0;
- scanf("%s %s %lld %f",new_temp->meno,new_temp->priezvisko,&rc,&mzda);
- new_temp->rodnecislo = rc;
- new_temp->mzda = mzda;
- int *pomocna= NULL;
- if(n==1)
- {
- new_temp->next = *head;
- *head = new_temp;
- }
- else
- {
- for(int i=0;i<n-2;i++)
- {
- old_temp=old_temp->next;
- }
- new_temp->next = old_temp->next;
- old_temp->next = new_temp;
- }
- }
- void odstranenie(int n,struct Zoznam** head)
- {
- printf("%p\n",head);
- struct Zoznam* old_temp= *head;
- if(n==0)
- {
- *head = old_temp->next;
- free(old_temp);
- return;
- }
- else
- {
- for(int i=0;i<n-2;i++)
- {
- old_temp=old_temp->next;
- }
- struct Zoznam* new_temp= old_temp->next;
- old_temp->next = new_temp->next;
- free(old_temp);
- }
- //
- }
- int overeniedatumu(int mesiac, int den)
- {
- if( (mesiac>12 || mesiac<1) && (mesiac<51 || mesiac>62))
- {
- return -1;
- }
- else if(
- (den>31 || den<1) && (mesiac!=1 || mesiac!=51) ||
- (den>28 || den<1) && (mesiac!=2 || mesiac!=52) ||
- (den>31 || den<1) && (mesiac!=3 || mesiac!=53) ||
- (den>30 || den<1) && (mesiac!=4 || mesiac!=54) ||
- (den>31 || den<1) && (mesiac!=5 || mesiac!=55) ||
- (den>30 || den<1) && (mesiac!=6 || mesiac!=56) ||
- (den>31 || den<1) && (mesiac!=7 || mesiac!=57) ||
- (den>31 || den<1) && (mesiac!=8 || mesiac!=58) ||
- (den>30 || den<1) && (mesiac!=9 || mesiac!=59) ||
- (den>31 || den<1) && (mesiac!=10 || mesiac!=60) ||
- (den>30 || den<1) && (mesiac!=11 || mesiac!=61) ||
- (den>31 || den<1) && (mesiac!=12 || mesiac!=62)
- )
- {
- return -1;
- }
- else return 1;
- }
- void checkRC(struct Zoznam** head)
- {
- printf("HERE: %p\n",head);
- struct Zoznam* temp = *head;
- int finalnum = 0;
- int index = 0;
- int removed = 0;
- while(temp!=NULL)
- {
- long long overenie = temp->rodnecislo;
- char num[11];
- sprintf(num,"%lld\n",overenie);
- int datum;
- int mesiac = (10 * (num[2]-'0') + num[3]-'0');
- int den = (10 * (num[4]-'0') + num[5]-'0');
- datum = overeniedatumu(mesiac,den);
- for(int i=0;i<5;i+=2)
- {
- int cislo = ( 10 * (num[i+0]-'0') +num[i+1]-'0' );
- finalnum+= cislo;
- }
- if(finalnum%11==0 && datum==1)
- {
- index++;
- }
- else{
- struct Zoznam* old_temp= *head;
- if(index==0){
- *head = old_temp->next;
- //free(old_temp);
- }else{
- for(int i=0;i<index-2;i++)
- {
- old_temp=old_temp->next;
- }
- struct Zoznam* new_temp= old_temp->next;
- old_temp->next = new_temp->next;
- //free(old_temp);
- }
- removed++;
- }
- temp=temp->next;
- finalnum=0;
- }
- printf("\nOdstranilo sa %d zaznamov\n",removed);
- }
- void removing(struct Zoznam** head)
- {
- struct Zoznam* temp;
- struct Zoznam* temp2;
- temp = *head;
- temp2 = temp->next;
- int index=1;
- while(temp!=NULL)
- {
- while(temp2!=NULL)
- {
- index++;
- if( strcmp(temp->meno,temp2->meno)==0 && strcmp(temp->priezvisko,temp2->priezvisko)==0 && temp->rodnecislo==temp2->rodnecislo && temp->mzda==temp2->mzda )
- {
- printf("Zhoda na indexe %d\n",index);
- //index--;
- }
- temp2=temp2->next;
- }
- temp = temp->next;
- //temp2 = temp->next;
- }
- }
- int main(int argc, char *argv[]) {
- struct Zoznam *head = NULL;
- printf("NACITANIE\n");
- nacitaj(&head);
- printf("\nVYPISANIE\n");
- vypis(&head);
- removing(&head);
- printf("\nVYPISANIE\n");
- vypis(&head);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement