Guest User

Untitled

a guest
May 25th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. typedef struct L {
  5. char letter ;
  6. struct L *next ;
  7. } List ; //defines structure for list
  8.  
  9. typedef struct LL {
  10. List *word ;
  11. struct LL *next ;
  12. } ListofList ; //defines structure for list of lists
  13.  
  14. List *insertList(char inputLetter, List *word) //construction of a list
  15. {
  16. List *Sentence = calloc( 1, sizeof( List ) ) ;
  17. Sentence-> letter = inputLetter ;
  18. Sentence-> next = word ;
  19. return Sentence ;
  20. }
  21.  
  22. ListofList *insertListofList(List *word, ListofList *inputSentence) //construction of list of lists
  23. {
  24. ListofList *Sentence = calloc (1, sizeof(ListofList)) ;
  25. Sentence->word = word ;
  26. Sentence->next = inputSentence ;
  27. return Sentence ;
  28. }
  29.  
  30. List *addList( char inputLetter, List *word ) //adding letters at the end of the list
  31. {
  32. if( word == NULL )
  33. {
  34. return insertList( inputLetter, NULL ) ;
  35. }
  36. else
  37. {
  38. List *w ;
  39. for( w = word ; w->next != NULL ; w = w->next )
  40. {
  41. }
  42. w->next = insertList( inputLetter, NULL ) ;
  43. return word ;
  44. }
  45. }
  46.  
  47. ListofList *read (void) //reading all the input
  48. {
  49. char inputLetter2 ;
  50. ListofList *sentence = NULL ;
  51. while (inputLetter2 != '.')
  52. {
  53. char inputLetter = '0';
  54. List *word =NULL ;
  55. while (inputLetter != '\n')
  56. {
  57. inputLetter = getchar() ;
  58. if (inputLetter =='.')
  59. {
  60. inputLetter = '\n' ;
  61. inputLetter2 = '.' ;
  62. }
  63. word = addList(inputLetter, word) ;
  64. }
  65. sentence = insertListofList(word, sentence) ;
  66. }
  67. return sentence ;
  68. }
  69.  
  70. int main( void )
  71. {
  72. char print ;
  73. ListofList *output = read() ;
  74. while (output != NULL)
  75. {
  76. print = putchar (output ->word -> letter) ;
  77. output->word = output->word-> next ;
  78. if (output->word == NULL)
  79. {
  80. output = output->next ;
  81. }
  82. }
  83. return 0 ;
  84. }
Add Comment
Please, Sign In to add comment