Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct L {
- char letter ;
- struct L *next ;
- } List ; //defines structure for list
- typedef struct LL {
- List *word ;
- struct LL *next ;
- } ListofList ; //defines structure for list of lists
- List *insertList(char inputLetter, List *word) //construction of a list
- {
- List *Sentence = calloc( 1, sizeof( List ) ) ;
- Sentence-> letter = inputLetter ;
- Sentence-> next = word ;
- return Sentence ;
- }
- ListofList *insertListofList(List *word, ListofList *inputSentence) //construction of list of lists
- {
- ListofList *Sentence = calloc (1, sizeof(ListofList)) ;
- Sentence->word = word ;
- Sentence->next = inputSentence ;
- return Sentence ;
- }
- List *addList( char inputLetter, List *word ) //adding letters at the end of the list
- {
- if( word == NULL )
- {
- return insertList( inputLetter, NULL ) ;
- }
- else
- {
- List *w ;
- for( w = word ; w->next != NULL ; w = w->next )
- {
- }
- w->next = insertList( inputLetter, NULL ) ;
- return word ;
- }
- }
- ListofList *read (void) //reading all the input
- {
- char inputLetter2 ;
- ListofList *sentence = NULL ;
- while (inputLetter2 != '.')
- {
- char inputLetter = '0';
- List *word =NULL ;
- while (inputLetter != '\n')
- {
- inputLetter = getchar() ;
- if (inputLetter =='.')
- {
- inputLetter = '\n' ;
- inputLetter2 = '.' ;
- }
- word = addList(inputLetter, word) ;
- }
- sentence = insertListofList(word, sentence) ;
- }
- return sentence ;
- }
- int main( void )
- {
- char print ;
- ListofList *output = read() ;
- while (output != NULL)
- {
- print = putchar (output ->word -> letter) ;
- output->word = output->word-> next ;
- if (output->word == NULL)
- {
- output = output->next ;
- }
- }
- return 0 ;
- }
Add Comment
Please, Sign In to add comment