fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. struct cadastro {
  6. char nome[50];
  7. int idade;
  8. char rua[50];
  9. int numero;
  10. };
  11.  
  12. void cadastro_print(struct cadastro *p) {
  13. printf("nome: %s\n", p->nome);
  14. printf("idade: %d\n", p->idade);
  15. printf("rua: %s\n", p->rua);
  16. printf("numero: %d\n", p->numero);
  17. printf("\n");
  18. }
  19.  
  20. int main(void) {
  21. struct cadastro c[4]; //Array[4] de estruturas
  22. for(int i = 0; i < 4; i++) {
  23. char tmp[100];
  24. fgets(c[i].nome, sizeof c[i].nome, stdin);
  25. c[i].nome[strlen(c[i].nome) - 1] = '\0'; // remove ENTER final
  26. fgets(tmp, sizeof tmp, stdin);
  27. sscanf(tmp, "%d", &c[i].idade);
  28. fgets(c[i].rua, sizeof c[i].rua, stdin);
  29. c[i].rua[strlen(c[i].rua) - 1] = '\0'; // remove ENTER final
  30. fgets(tmp, sizeof tmp, stdin);
  31. sscanf(tmp, "%d", &c[i].numero);
  32. }
  33. for (int i = 0; i < 4; i++) cadastro_print(c + i);
  34. // system("pause");
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0s 2012KB
stdin
Primeiro Nome
42
Primeira Rua
42
Segundo Nome
24
Segunda Rua
24
tres
3
tres
3
Ultimo
10000
Ultimo
10000
stdout
nome: Primeiro Nome
idade: 42
rua: Primeira Rua
numero: 42

nome: Segundo Nome
idade: 24
rua: Segunda Rua
numero: 24

nome: tres
idade: 3
rua: tres
numero: 3

nome: Ultimo
idade: 10000
rua: Ultimo
numero: 10000