Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define NUMBER 3
- typedef struct
- {
- char*nume;
- char*prenume;
- int varsta;
- int nota[NUMBER];
- float medie;
- } STUDENT;
- STUDENT conversie(char*nume, char*prenume, int varsta, int note[NUMBER])
- {
- STUDENT s;
- s.nume=nume;
- s.prenume=prenume;
- s.varsta=varsta;
- for(int i=0; i<NUMBER; i++)
- s.nota[i]=note[i];
- return s;
- }
- void incrementare(STUDENT *s)
- {
- for(int i=0; i<NUMBER; i++)
- {
- if(s->nota[i]<10)
- s->nota[i]++;
- }
- }
- void afisare(STUDENT s)
- {
- printf("%s %s %d %d %d\n", s.nume, s.prenume, s.nota[0], s.nota[1],s.nota[2]);
- }
- int main()
- {
- FILE* f=fopen("nume.txt","r");
- if(f==NULL)
- return -1;
- int n;
- fscanf(f,"%d",&n);
- printf("%d\n",n);
- STUDENT *lista=calloc(n,sizeof(STUDENT));
- for(int i=0; i<n; i++)
- {
- char* nume = malloc(20*sizeof(char));
- char* prenume = malloc(20*sizeof(char));
- int varsta;
- fscanf(f,"%s %s %d",nume, prenume, &varsta);
- int note[NUMBER];
- for(int j=0; j<NUMBER; j++)
- fscanf(f,"%d", ¬e[j]);
- STUDENT s=conversie(nume,prenume,varsta,note);
- lista[i]=s;
- lista[i].medie=(float)(note[0]+note[1]+note[2])/NUMBER;
- printf("%s %s %f\n", lista[i].nume, lista[i].prenume, lista[i].medie);
- }
- for(int j=0; j<n; j++)
- {
- incrementare(&lista[j]);
- afisare(lista[j]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment