Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define VSTUP "zavodnici.txt"
  5. #define VYSTUP "vysledkova_listina.txt"
  6. /*
  7. int prevodCasu(const char *cas){
  8. char *pch;
  9. pch = strtok(str)
  10. }
  11. */
  12. int main(int argc, char** argv) {
  13. typedef struct{
  14. int cislo;
  15. char prijmeni[40];
  16. char jmeno[20];
  17. char cas_prvni[10];
  18. char cas_druhy[10];
  19. }ZAVODNIK;
  20. ZAVODNIK * zavodnici = NULL;
  21. char mystring[100];
  22. int i,r=0;
  23. FILE * soubor;
  24. soubor = fopen(VSTUP,"r");
  25. if(soubor == NULL){
  26. printf("Chyba nacteni souboru %s, program bude ukoncen.\n",VSTUP);
  27. return (EXIT_FAILURE);
  28. }
  29. zavodnici = (ZAVODNIK *)malloc(sizeof(ZAVODNIK));
  30. fgets(mystring,100,soubor);
  31. while(fscanf(soubor,"%d %s %s %s %s",&zavodnici[r].cislo,zavodnici[r].prijmeni,
  32. zavodnici[r].jmeno,zavodnici[r].cas_prvni,zavodnici[r].cas_druhy)==5){
  33. r++;
  34. zavodnici = (ZAVODNIK *)realloc(zavodnici,(r + 1)*sizeof(ZAVODNIK));
  35. }
  36.  
  37. printf("S T A R T O V N I L I S T I N A - S L A L O M Z E N Y\n"
  38. "---------------------------------------------------------\n"
  39. "startovni cislo | prijmeni | jmeno | cas 1. kola|cas 2. kola\n"
  40. "---------------------------------------------------------\n");
  41. for(i=0;i<r;i++){
  42. printf("%10d|%13s|%8s|%11s|%11s\n",zavodnici[i].cislo,zavodnici[i].prijmeni,
  43. zavodnici[i].jmeno,zavodnici[i].cas_prvni,zavodnici[i].cas_druhy);
  44. }
  45. printf("---------------------------------------------------------\n");
  46.  
  47. if(fclose(soubor)==EOF){
  48. printf("Soubor %s nebyl uzavren.\n",VSTUP);
  49. return (EXIT_FAILURE);
  50. }
  51.  
  52.  
  53. soubor = fopen(VYSTUP,"w");
  54. if(soubor == NULL){
  55. printf("Soubor %s nebyl vytvoren, program bude ukoncen.\n",VYSTUP);
  56. return (EXIT_FAILURE);
  57. }
  58.  
  59. fprintf(soubor,"V Y S L E D K O V A L I S T I N A\n"
  60. "---------------------------------------"
  61. "poradi|cislo| prijmeni | jmeno | 1.kolo| 2.kolo| celkem| ztrata\n");
  62. for(i=0;i<r;i++){
  63. //fprintf(soubor,"%6d|%5s|%12s|%8s|%7s|%7s|%7s|%9s\n",zavodnici[i].cislo,zavodnici[i].prijmeni,
  64. //zavodnici[i].jmeno,zavodnici[i].cas_prvni,zavodnici[i].cas_druhy);
  65. }
  66.  
  67.  
  68. if(fclose(soubor)==EOF){
  69. printf("Soubor %s nebyl uzavren.\n",VYSTUP);
  70. return (EXIT_FAILURE);
  71. }
  72. else{
  73. printf("Soubor %s byl vytvoren.\n",VYSTUP);
  74. }
  75.  
  76. return (EXIT_SUCCESS);
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement