1
I don’t know why you can’t allocate!!
struct dados {
int numero;
char nome[5];
};
typedef struct dados Das;
void manipula_um_par (struct dados *a, int b) {
a[b].numero = a[b].numero /2;
}
void manipula_pares(struct dados *x, int w) {
int z;
for (z = 0; z < w; z++) {
if (x[z].numero % 2 == 0) {
manipula_um_par(x,z);
}
}
}
int main()
{
Das *p;
int k;
printf("Qual sera o numero de alunos?\n");
scanf("%d",&k);
p = (Das*)malloc(k*sizeof(Das));
Das v[p];
int x;
for (x = 0; x < k; x++) {
printf("\nDigite o nome do %d aluno: ", x+1);
scanf("%s", v[p].nome);
printf("\nDigite o %d numero: ", x+1);
scanf("%d",&v[p].numero);
}
manipula_pares(v, k);
for (x=0; x < k; x++) {
printf("--- %d ", v[p].numero);
}
return 0;
}
p
is a Pointer for a data structure and therefore cannot serve as an input for an array inDas v[p]
.– user142154
then what should I do to be able to allocate this vector of structs??
– Arthur
the vector you have already managed to allocate is the
Das *p
. Excludes theDas v[]
of your code and in its place uses thep
with a maximum rate ofk - 1
.– user142154