Florii11

1

Feb 23rd, 2021
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define NUMBER 3
  5.  
  6. typedef struct
  7. {
  8.     char*nume;
  9.     char*prenume;
  10.     int varsta;
  11.     int nota[NUMBER];
  12.  
  13. } STUDENT;
  14.  
  15. STUDENT conversie(char*nume, char*prenume, int varsta, int note[NUMBER])
  16. {
  17.     STUDENT s;
  18.     s.nume=nume;
  19.     s.prenume=prenume;
  20.     s.varsta=varsta;
  21.     for(int i=0; i<NUMBER; i++)
  22.         s.nota[i]=note[i];
  23.     return s;
  24. }
  25.  
  26. int main()
  27. {
  28.     FILE* f=fopen("nume.txt","r");
  29.     if(f==NULL)
  30.         return -1;
  31.     int n;
  32.     fscanf(f,"%d",&n);
  33.     printf("%d\n",n);
  34.  
  35.     STUDENT *lista;
  36.     lista=calloc(n,sizeof(STUDENT));
  37.  
  38.     for(int i=0;i<n;i++)
  39.     {
  40.         char nume[20], prenume[20];
  41.         int varsta;
  42.         fscanf(f,"%s %s %d",nume, prenume, &varsta);
  43.         int note[NUMBER];
  44.         for(int j=0;j<NUMBER;j++)
  45.             fscanf(f,"%d", &note[j]);
  46.         lista[i]=conversie(nume,prenume,varsta,note);
  47.         printf("%s %s\n", lista[i].nume, lista[i].prenume);
  48.     }
  49.  
  50.     return 0;
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment