Advertisement
hmcristovao

Lista 08 - exercício 11

Aug 7th, 2013
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define MAX 100
  5. #define MAX_TAM_NOME 50
  6. char* solicitaNome(void);
  7. int main() {
  8.    int qtde, i;
  9.    char* vet[MAX];
  10.    printf("Quants nomes? ");
  11.    scanf("%d",&qtde);
  12.    for(i=0; i<qtde; i++) {
  13.        vet[i] = solicitaNome();
  14.    }
  15.  
  16.    printf("\nNomes:\n");
  17.    for(i=0; i<qtde; i++) {
  18.        printf("%s \n",vet[i]);
  19.    }
  20.    return 0;
  21. }
  22. char* solicitaNome(void) {
  23.    char *nome;
  24.    char aux[MAX_TAM_NOME];
  25.    printf("Entre com o nome: ");
  26.    fflush(stdin);
  27.    gets(aux);
  28.    nome = (char*)malloc(strlen(aux)+1);
  29.    strcpy(nome,aux);
  30.    return nome;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement