Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*CABEÇALHO
- Arquivo: LISTA 08 - Exercício 11.c
- Objetivo: Criar uma lista de nomes usando ponteiros.
- Autor(a): Ramon Borges.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- //PROTOTIPO DE FUNÇÕES
- char* solicitaNome(void);
- int main()
- {
- int qtde, i;
- char *listaNomes;
- printf("Quantos nomes serao digitados ? : ");
- scanf("%d", &qtde);
- listaNomes = (char*) malloc(qtde*sizeof(char));
- for(i = 0; i < qtde; i++, listaNomes++)
- listaNomes = solicitaNome();
- free(listaNomes);
- return 0;
- }
- char* solicitaNome(void)
- {
- int tamanho;
- char nome[50], *p;
- printf("\nInforme seu nome: ");
- fflush(stdin);
- gets(nome);
- tamanho = strlen(nome);
- p = (char*) malloc(tamanho * sizeof(char));
- p = nome;
- return p;
- }
Advertisement
Add Comment
Please, Sign In to add comment