All pastes #536294 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-06-04 10:26 UTC
rendered paste body
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct _student {
   long sifra;
   char imeprez[41];
   short ispiti;
   float ocjena;
};
int main(int argc, char *argv[])
{
   FILE *fin, *fout;
   char buffer[32];
   const char *end = "NONAME";
   int broj = 0;
   struct _student student;
   if (argc < 3) {
      printf("Greska: ime datoteke nije definirano\nPrimjer: %s ime_datoteke nova_datoteka", argv[0]);
      getche();
      return 1;
   }
   if ((fin = fopen(argv[1], "rb")) == NULL) {
      printf("Greska, ne mogu otvoriti datoteku %s\n", argv[1]);
      getche();
      return 1;
   }
   if ((fout = fopen(argv[2], "w")) == NULL) {
      printf("Greska, ne mogu otvoriti datoteku %s\n", argv[2]);
      getche();
      return 1;
   }
   while (!feof(fin)) {
      memset(&student, 0, sizeof(student));
      fread(&student, sizeof(student), 1, fin);
      if (student.sifra == 0)
         break;      
      fprintf(fout, "%d;%s;%d;%f\n", student.sifra, student.imeprez, student.ispiti, student.ocjena);      
   }
   fclose(fout);
   fclose(fin);
   getche();
   return 0;
}