Print list of names in C

1

The truth is I'm a bit lost on this from the pointers and I need help with a program I'm supposed to enter n for the number of names the list will have, enter the names one by one and at the end it should show me in the form of a list the names that I enter but in the end it only shows me the last name that I entered, thanks in advance.

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>

void leer_cadena(int &);
void escribir_cadena(int &,char *);
char *nombre;

int main(){
    int n,i;
    printf("Ingresa el numero de nombres: ");
    scanf("%d",&n);
    leer_cadena(n);
    escribir_cadena(n,nombre);
    getch();
}

void leer_cadena(int &n)
{
    int L,i;
    char cadena[30];
    for (i=0;i<n;i++)
    {
        printf("\nIngresa el nombre: ");
        fflush(stdin);
        gets(cadena);
        L=strlen(cadena);
        nombre=(char *)malloc(L*sizeof(char));
        strcpy(nombre,cadena);
    }
}

void escribir_cadena(int &n,char *cad){
    int i; 
    for (i=0;i<n;i++)
    {
        while(*cad)
        {
            putchar(*cad++);    
        }
    }
}
    
asked by gamemode19 14.11.2018 в 05:53
source

0 answers