Mrain

upis u datoteku 4

Sep 26th, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. typedef struct{
  5.    
  6.     int redBr;
  7.     char ime_prezime[50];
  8.     int visina[3];
  9. }at_vis;
  10.  
  11. void Unos(at_vis *, int);
  12.  
  13. int main()
  14. {
  15.     at_vis *a;
  16.     FILE *f;
  17.     f=fopen("atletika.txt","w");
  18.     int n;
  19.     printf("Broj natjecatelja:");
  20.     scanf("%d", &n);
  21.  
  22.     a =(at_vis*)malloc(n*sizeof(at_vis));
  23.  
  24.     Unos(a,n);
  25.  
  26.     fprintf(f,"REDNI BROJ\t IME\t SPLIT OSLO TOKIO\n");
  27.  
  28.     for (int i=0;i<n;i++)
  29.     {
  30.         fprintf(f,"\n%d\t", a[i].redBr);
  31.         fprintf(f,"%s\t", a[i].ime_prezime);
  32.         for(int j=0;j<3;j++)
  33.         {
  34.             fprintf(f,"%d ", a[i].visina[j]);
  35.         }
  36.     }
  37.  
  38.     fclose(f);
  39. }
  40.  
  41. void Unos(at_vis *a, int n)
  42. {
  43.     for(int i=0;i<n;i++)
  44.     {
  45.         printf("%d. natjecatelj:", i+1);
  46.         printf("Redni broj:");
  47.         scanf("%d", &a[i].redBr);
  48.         printf("Ime:");
  49.         scanf("%s", a[i].ime_prezime);
  50.         for(int j=0;j<3;j++)
  51.         {
  52.             printf("%d. visina", j+1);
  53.             scanf("%d", &a[i].visina[j]);
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment