ramontricolor12

LISTA 08 - Exercício 11

Aug 12th, 2013
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.81 KB | None | 0 0
  1. /*CABEÇALHO
  2.     Arquivo: LISTA 08 - Exercício 11.c
  3.     Objetivo: Criar uma lista de nomes usando ponteiros.
  4.     Autor(a): Ramon Borges.
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. //PROTOTIPO DE FUNÇÕES
  11. char* solicitaNome(void);
  12.  
  13. int main()
  14. {
  15.     int qtde, i;
  16.     char *listaNomes;
  17.  
  18.     printf("Quantos nomes serao digitados ? : ");
  19.     scanf("%d", &qtde);
  20.     listaNomes = (char*) malloc(qtde*sizeof(char));
  21.     for(i = 0; i < qtde; i++, listaNomes++)
  22.         listaNomes = solicitaNome();
  23.     free(listaNomes);
  24.     return 0;
  25. }
  26.  
  27. char* solicitaNome(void)
  28. {
  29.     int tamanho;
  30.     char nome[50], *p;
  31.     printf("\nInforme seu nome: ");
  32.     fflush(stdin);
  33.     gets(nome);
  34.     tamanho = strlen(nome);
  35.     p = (char*) malloc(tamanho * sizeof(char));
  36.     p = nome;
  37.     return p;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment