I hope you can help me, It's really important. Please I have a program which I need to print a name 23 times char by char using linked lists. I have made it work printing it once, even though I have a for loop I can't make it print the text 23 times. Please help. I don't know where to start.
You would really help me a lot by answering this question, I've tried a lot but im still not able to understand how to do it. Thanks in advance.
#include <conio.h> #include <locale.h> #include <stdio.h> #include <stdlib.h> typedef struct L { char c; struct L *next; }List; List *l = NULL; // list head, we'll prepend nodes here int c; // variable for current read character List *getInput(void) { while ((c = getchar()) != '\n') { // read until enter List *n = calloc(1, sizeof(List)); // create new list node n->c = c; // store read character in that node n->next = l; // prepend newly created node to our list l = n; // store newly created node as head of list } return l; } int main ( void ) { printf("Ingresa tu nombre.\n"); getInput(); printf("\n"); int i = 0; for(i;i<23; //I tried something like l=1; here bit it didn't work. while (l != NULL) { // while we have not reached end of list putchar(l->c); // print character stored in list printf("\n"); l = l->next; // and advance to next list node } } return 0; }
printf("\n")out of and after the while loop.