Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. typedef struct{
  6.  
  7. char kod[20+1];
  8. int iznos;
  9. int dan;
  10. int mjesec;
  11. int godina;
  12. int sat;
  13. int min;
  14. int sec;
  15.  
  16. }lista;
  17.  
  18. struct dozvola{
  19.  
  20. char kod1[20+1];
  21. int sat1;
  22. int min1;
  23. int sec1;
  24. int broj;
  25.  
  26. }lista1[30];
  27.  
  28.  
  29. int main()
  30. {
  31. char usporedba[5]={0};
  32. int i,j,l,a,swap,b;
  33. int niz[30];
  34. lista r;
  35.  
  36. scanf("%s",usporedba);
  37.  
  38. l=strlen(usporedba);
  39.  
  40. FILE *ulaz=NULL;
  41.  
  42. ulaz=fopen("creepto.val","rb");
  43.  
  44. if(ulaz == NULL){
  45. printf("Neuspjesno otvaranje datoteke!");
  46. exit(1);
  47. }
  48.  
  49. a=0;
  50. while(!feof(ulaz)){
  51. fread(&r,sizeof(lista),1,ulaz);
  52.  
  53. j=0;
  54.  
  55. for (i=0;i<l;i++){
  56. char *slovo=strchr(r.kod,usporedba[i]);
  57. if(slovo != NULL){
  58. j++;
  59.  
  60. if(j==l){
  61.  
  62. b=(r.sat*3600)+(r.min*60)+r.sec;
  63.  
  64. strcpy(lista1[a].kod1,r.kod);
  65.  
  66. lista1[a].sat1=r.sat;
  67. lista1[a].min1=r.min;
  68. lista1[a].sec1=r.sec;
  69. lista1[a].broj=b;
  70.  
  71. niz[a]=b;
  72.  
  73. a++;
  74.  
  75. }
  76. }
  77. }
  78. }
  79. fclose(ulaz);
  80.  
  81. for (i=0;i<(a-1);i++){
  82. for(j=0;j<(a-i-1);j++){
  83. if (niz[j]>niz[j+1]){
  84. swap=niz[j];
  85. niz[j]=niz[j+1];
  86. niz[j+1]=swap;
  87. }
  88. }
  89. }
  90.  
  91. for (i=0;i<a;i++){
  92. for (j=0;j<a;j++){
  93. if (niz[i]==lista1[j].broj){
  94.  
  95. printf("%s@",lista1[j].kod1);
  96.  
  97. if (lista1[j].sat1<10){
  98. printf("%02d:", lista1[j].sat1);
  99. }else{
  100. printf("%d:", lista1[j].sat1);
  101. }
  102.  
  103. if (lista1[j].min1<10){
  104. printf("%02d:", lista1[j].min1);
  105. }else{
  106. printf("%d:", lista1[j].min1);
  107. }
  108.  
  109. if (lista1[j].sec1<10){
  110. printf("%02d", lista1[j].sec1);
  111. }else{
  112. printf("%d", lista1[j].sec1);
  113. }
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120. }
  121. }
  122. printf("\n");
  123. }
  124.  
  125.  
  126.  
  127. return 0;
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement