Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define VSTUP "zavodnici.txt"
- #define VYSTUP "vysledkova_listina.txt"
- /*
- int prevodCasu(const char *cas){
- char *pch;
- pch = strtok(str)
- }
- */
- int main(int argc, char** argv) {
- typedef struct{
- int cislo;
- char prijmeni[40];
- char jmeno[20];
- char cas_prvni[10];
- char cas_druhy[10];
- }ZAVODNIK;
- ZAVODNIK * zavodnici = NULL;
- char mystring[100];
- int i,r=0;
- FILE * soubor;
- soubor = fopen(VSTUP,"r");
- if(soubor == NULL){
- printf("Chyba nacteni souboru %s, program bude ukoncen.\n",VSTUP);
- return (EXIT_FAILURE);
- }
- zavodnici = (ZAVODNIK *)malloc(sizeof(ZAVODNIK));
- fgets(mystring,100,soubor);
- while(fscanf(soubor,"%d %s %s %s %s",&zavodnici[r].cislo,zavodnici[r].prijmeni,
- zavodnici[r].jmeno,zavodnici[r].cas_prvni,zavodnici[r].cas_druhy)==5){
- r++;
- zavodnici = (ZAVODNIK *)realloc(zavodnici,(r + 1)*sizeof(ZAVODNIK));
- }
- 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"
- "---------------------------------------------------------\n"
- "startovni cislo | prijmeni | jmeno | cas 1. kola|cas 2. kola\n"
- "---------------------------------------------------------\n");
- for(i=0;i<r;i++){
- printf("%10d|%13s|%8s|%11s|%11s\n",zavodnici[i].cislo,zavodnici[i].prijmeni,
- zavodnici[i].jmeno,zavodnici[i].cas_prvni,zavodnici[i].cas_druhy);
- }
- printf("---------------------------------------------------------\n");
- if(fclose(soubor)==EOF){
- printf("Soubor %s nebyl uzavren.\n",VSTUP);
- return (EXIT_FAILURE);
- }
- soubor = fopen(VYSTUP,"w");
- if(soubor == NULL){
- printf("Soubor %s nebyl vytvoren, program bude ukoncen.\n",VYSTUP);
- return (EXIT_FAILURE);
- }
- fprintf(soubor,"V Y S L E D K O V A L I S T I N A\n"
- "---------------------------------------"
- "poradi|cislo| prijmeni | jmeno | 1.kolo| 2.kolo| celkem| ztrata\n");
- for(i=0;i<r;i++){
- //fprintf(soubor,"%6d|%5s|%12s|%8s|%7s|%7s|%7s|%9s\n",zavodnici[i].cislo,zavodnici[i].prijmeni,
- //zavodnici[i].jmeno,zavodnici[i].cas_prvni,zavodnici[i].cas_druhy);
- }
- if(fclose(soubor)==EOF){
- printf("Soubor %s nebyl uzavren.\n",VYSTUP);
- return (EXIT_FAILURE);
- }
- else{
- printf("Soubor %s byl vytvoren.\n",VYSTUP);
- }
- return (EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement