Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct {
- char ime[30];
- char prezime[50];
- unsigned long matbr;
- float placa;
- char oznaka;
- } osoba;
- int main(){
- int n, i, tmp;
- FILE* fpla = NULL;
- fpla=fopen("Place.dat", "wb");
- if(fpla==NULL)
- printf("Nista s toga!");
- printf("Broj padataka:");
- scanf("%d", &n);
- osoba o;
- osoba *o1;
- o1=(osoba*)malloc(n*sizeof(osoba));
- for(i=0; i<n; i++){
- scanf("%30[^,], %50[^,], %ld, %f, %c ", &o.ime,
- &o.prezime, &o.matbr, &o.placa, &o.oznaka);
- fwrite(&o, sizeof(osoba), 1, fpla);
- }
- fclose(fpla);
- fpla=fopen("Place.dat", "rb");
- for(i=0; i<n; i++){
- fread(o1, sizeof(osoba), 1, fpla);
- printf("%s %s %ld %.2f %c ", o1[i].ime,
- o1[i].prezime, o1[i].matbr, o1[i].placa, o1[i].oznaka);
- }
- free(o1);
- fclose(fpla);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment