Students were asked to replicate a teacher-designed scheme in the classroom. In this scheme he made a vector, within each position he made a matrix and within each position of the matrix he designed a structure containing name, address and age. Make it clear that I am not asking you to solve it for me, I just want you to explain the logic of this exercise.
Here's what I've done so far:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
struct Pessoa{
char nome[40];
char endereco[100];
int idade;
};
void mostrar(Pessoa vetor[][2]){
for(int i=0; i<2; i++){
for(int j=0; j<2; j++){
printf("\nCOD-%d\n", i);
printf("\tNome: %s", vetor[i][j].nome);
printf("\n\tEndereco: %s", vetor[i][j].endereco);
printf("\n\tIdade: %d", vetor[i][j].idade);
}
printf("\n");
}
}
int main(void){
Pessoa clientes[2][2];
for(int i=0; i<2; i++)
for(int j=0; j<2; j++){
fflush(stdin);
printf("\nCOD-%d%d\n", i,j);
printf("\tNome: ");
gets(clientes[i][j].nome);
printf("\tEndereco: ");
gets(clientes[i][j].endereco);
printf("\tIdade: ");
scanf("%d", &clientes[i][j].idade);
}
system("cls");
mostrar(clientes);
return 0;
}