Advertisement
renix1

Registro

Feb 25th, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. // definição de um registro aluno
  6. struct aluno {
  7.     char *nome;
  8.     char *ru;
  9. };
  10.  
  11. int main (void) {
  12.     int nEstudantes = 0; // numero de estudantes
  13.     printf("Digite o numero de estudantes que deseja cadastrar: ");
  14.     scanf("%d", &nEstudantes);
  15.     for (int i=0; i<nEstudantes; i++) {
  16.         struct aluno al; // declaração de um registro aluno
  17.         printf("Digite o nome do estudante nº%d: ", i);
  18.         char *nome = malloc(sizeof(char[50]));
  19.         scanf("%s", nome);
  20.         al.nome = nome;
  21.         printf("O aluno de nº %d foi cadastrado com o nome %s\n", i+1, al.nome);
  22.         free(nome);
  23.     }
  24.  
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement