0
How can I pass some data from one vector to another? I’m doing an exercise and I need to take several data from several students at struct
and place in a vector. Then I need to check if they were approved or failed and divide into other 2 vectors.
I need a for
to go through the main vector and check the notes, but how do I move other vectors and allocate the data without leaving blank spaces?
void leitura (struct medialunos vet[tf], int vet1[tf], int vet2[tf]){
int i, j;
for (i=0;i<tf;i++){
for (j=0; j<tf;j++){
printf ("\nEntre com a matricula: ");
scanf ("%d", &vet[i].matricula);
printf ("\nEntre com o nome: ");
fflush (stdin);
fgets (vet[i].nome,20,stdin);
printf ("\nEntre com a media final: ");
scanf ("%lf", &vet[i].mediafinal);
printf ("\n_____________________________________________\n");
if (vet[i].mediafinal >= 6){
vet1[j] = vet[i];
else
vet2[j] = vet[i];
}
}
}
}
Set your function to: void reading (struct medialunos vet[], int vet1[], int vet2[], int Tf){. It doesn’t make much sense for this two for command, how do you want to assign an element of an int vector an element of a medial struct vector? For vet1 and vet2 vectors use different indexes for each of them, initialized with zero and incremented with each new element added
– anonimo