Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.85 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. struct Zoznam
  6. {
  7. char meno[31];
  8. char priezvisko[31];
  9. long long rodnecislo;
  10. float mzda;
  11. struct Zoznam* next;
  12. } Zoznam;
  13.  
  14. void nacitaj(struct Zoznam **head) //fully working
  15. {
  16. printf("%p\n",head);
  17. FILE *fr;
  18. fr = fopen("zamestnanci.txt","r");
  19. if(fr!=NULL)
  20. {
  21. int pocet=0;
  22. while(1)
  23. {
  24. long long rc=0;
  25. float plat=0;
  26.  
  27. struct Zoznam* temp= (struct Zoznam*) malloc(sizeof(struct Zoznam));
  28. temp->next=NULL;
  29.  
  30. if(fscanf(fr,"%s %s %lld %f",temp->meno,temp->priezvisko,&rc,&plat)==EOF)
  31. {
  32. break;
  33. }
  34.  
  35. temp->rodnecislo = rc;
  36. temp->mzda = plat;
  37.  
  38. if(*head==NULL)
  39. {
  40. *head = temp;
  41. }
  42. else
  43. {
  44. struct Zoznam* end;
  45. end = *head;
  46. while(end->next!=NULL)
  47. {
  48. end = end->next;
  49. }
  50. end->next=temp;
  51. }
  52. pocet++;
  53. }
  54. printf("Nacitalo sa %d zaznamov\n",pocet);
  55. }
  56. }
  57.  
  58. void vypis(struct Zoznam** head) //fully working
  59. {
  60. printf("%p\n",head);
  61. struct Zoznam *temp=*head;
  62. int pos = 1;
  63. while(temp!=NULL)
  64. {
  65. printf("%d. %s %s %lld %.2f\n",pos,temp->meno,temp->priezvisko,temp->rodnecislo,temp->mzda);
  66. pos++;
  67. temp=temp->next;
  68. }
  69. printf("\n");
  70. }
  71.  
  72. void pridanie(struct Zoznam** head) //fully working
  73. {
  74. struct Zoznam* new_temp= (struct Zoznam*) malloc(sizeof(struct Zoznam));
  75. struct Zoznam* old_temp= *head;
  76. new_temp->next = NULL;
  77. int n;
  78.  
  79. printf("Zadaj cislo pozicie\n");
  80. scanf("%d",&n);
  81. printf("Zadaj meno \n");
  82. long long rc = 0;
  83. float mzda = 0;
  84. scanf("%s %s %lld %f",new_temp->meno,new_temp->priezvisko,&rc,&mzda);
  85.  
  86. new_temp->rodnecislo = rc;
  87. new_temp->mzda = mzda;
  88.  
  89. int *pomocna= NULL;
  90. if(n==1)
  91. {
  92. new_temp->next = *head;
  93. *head = new_temp;
  94. }
  95.  
  96. else
  97. {
  98. for(int i=0;i<n-2;i++)
  99. {
  100. old_temp=old_temp->next;
  101. }
  102.  
  103. new_temp->next = old_temp->next;
  104. old_temp->next = new_temp;
  105. }
  106. }
  107.  
  108. void odstranenie(int n,struct Zoznam** head)
  109. {
  110. printf("%p\n",head);
  111. struct Zoznam* old_temp= *head;
  112. if(n==0)
  113. {
  114. *head = old_temp->next;
  115. free(old_temp);
  116. return;
  117. }
  118. else
  119. {
  120. for(int i=0;i<n-2;i++)
  121. {
  122. old_temp=old_temp->next;
  123. }
  124.  
  125. struct Zoznam* new_temp= old_temp->next;
  126. old_temp->next = new_temp->next;
  127. free(old_temp);
  128. }
  129. //
  130. }
  131.  
  132. int overeniedatumu(int mesiac, int den)
  133. {
  134. if( (mesiac>12 || mesiac<1) && (mesiac<51 || mesiac>62))
  135. {
  136. return -1;
  137. }
  138.  
  139. else if(
  140. (den>31 || den<1) && (mesiac!=1 || mesiac!=51) ||
  141. (den>28 || den<1) && (mesiac!=2 || mesiac!=52) ||
  142. (den>31 || den<1) && (mesiac!=3 || mesiac!=53) ||
  143. (den>30 || den<1) && (mesiac!=4 || mesiac!=54) ||
  144. (den>31 || den<1) && (mesiac!=5 || mesiac!=55) ||
  145. (den>30 || den<1) && (mesiac!=6 || mesiac!=56) ||
  146. (den>31 || den<1) && (mesiac!=7 || mesiac!=57) ||
  147. (den>31 || den<1) && (mesiac!=8 || mesiac!=58) ||
  148. (den>30 || den<1) && (mesiac!=9 || mesiac!=59) ||
  149. (den>31 || den<1) && (mesiac!=10 || mesiac!=60) ||
  150. (den>30 || den<1) && (mesiac!=11 || mesiac!=61) ||
  151. (den>31 || den<1) && (mesiac!=12 || mesiac!=62)
  152. )
  153. {
  154. return -1;
  155. }
  156. else return 1;
  157. }
  158.  
  159. void checkRC(struct Zoznam** head)
  160. {
  161. printf("HERE: %p\n",head);
  162. struct Zoznam* temp = *head;
  163. int finalnum = 0;
  164. int index = 0;
  165. int removed = 0;
  166. while(temp!=NULL)
  167. {
  168. long long overenie = temp->rodnecislo;
  169. char num[11];
  170. sprintf(num,"%lld\n",overenie);
  171.  
  172. int datum;
  173. int mesiac = (10 * (num[2]-'0') + num[3]-'0');
  174. int den = (10 * (num[4]-'0') + num[5]-'0');
  175. datum = overeniedatumu(mesiac,den);
  176.  
  177. for(int i=0;i<5;i+=2)
  178. {
  179. int cislo = ( 10 * (num[i+0]-'0') +num[i+1]-'0' );
  180. finalnum+= cislo;
  181. }
  182. if(finalnum%11==0 && datum==1)
  183. {
  184. index++;
  185. }
  186. else{
  187. struct Zoznam* old_temp= *head;
  188. if(index==0){
  189. *head = old_temp->next;
  190. //free(old_temp);
  191. }else{
  192. for(int i=0;i<index-2;i++)
  193. {
  194. old_temp=old_temp->next;
  195. }
  196. struct Zoznam* new_temp= old_temp->next;
  197. old_temp->next = new_temp->next;
  198. //free(old_temp);
  199. }
  200. removed++;
  201. }
  202. temp=temp->next;
  203. finalnum=0;
  204. }
  205. printf("\nOdstranilo sa %d zaznamov\n",removed);
  206. }
  207.  
  208. void removing(struct Zoznam** head)
  209. {
  210. struct Zoznam* temp;
  211. struct Zoznam* temp2;
  212.  
  213. temp = *head;
  214. temp2 = temp->next;
  215.  
  216. int index=1;
  217. while(temp!=NULL)
  218. {
  219. while(temp2!=NULL)
  220. {
  221. index++;
  222. if( strcmp(temp->meno,temp2->meno)==0 && strcmp(temp->priezvisko,temp2->priezvisko)==0 && temp->rodnecislo==temp2->rodnecislo && temp->mzda==temp2->mzda )
  223. {
  224. printf("Zhoda na indexe %d\n",index);
  225. //index--;
  226. }
  227. temp2=temp2->next;
  228. }
  229. temp = temp->next;
  230. //temp2 = temp->next;
  231. }
  232. }
  233.  
  234. int main(int argc, char *argv[]) {
  235. struct Zoznam *head = NULL;
  236. printf("NACITANIE\n");
  237. nacitaj(&head);
  238.  
  239. printf("\nVYPISANIE\n");
  240. vypis(&head);
  241.  
  242. removing(&head);
  243.  
  244. printf("\nVYPISANIE\n");
  245. vypis(&head);
  246.  
  247. return 0;
  248. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement