0
In that code:
#include <stdio.h>
#include <stdlib.h>
struct cadastro {
char nome[50];
int idade;
char rua[50];
int numero;
};
int main()
{
struct cadastro c[4]; //Array[4] de estruturas
for(int i=0; i<4; i++) {
gets(c[i].nome);
scanf("%d", &c[i].idade);
gets(c[i].rua);
scanf("%d", &c[i].numero);
}
system("pause");
return 0;
}
How to print all the elements of the struct, without doing it manually with a printf. For he will exhibit four times.
I think the title is poorly formulated.
– Leonardo
Tip 1: Do not use
gets()
; it is impossible to use this function safely; the function was removed from the C Standard in 2011; replaced byfgets()
. Suggestion 2: Do not mixfgets()
(gets()
) withscanf()
; always usefgets()
and, if necessary,sscanf()
.– pmg
@pmg I’m reading the C99 version.
– Leonardo