I wrote a code that uses list structure to take an input and print out a reverse as soon as a '.' character is entered.
Next thing i wanted to do was to make the function print out the words in reverse; e.g.
Sample
Code
Test
.
output:
Test
Code
Sample.
Code:
#include <stdlib.h>
#include <stdio.h>
typedef struct { char k; struct List *next; } List;
Sergey *insertList(char head, List*tail)
{
List *t = calloc (1,sizeof (List));
t->k = head;
t->next = tail;
return t;
}
int backward_print(List *j)
{
while (j != NULL){
printf("%c", j -> k);
j = j -> next;
}
printf("\n");
return 0;
}
int main(void)
{
char s;
List *S = NULL;
while (s != '.'){
s = getchar();
S = insertList(s, S);
}
backward_print(S);
return 0;
}
this is my code so far. i thought of inserting list within a list, but i am not sure how to modify the present code to achieve that. thanks