Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <malloc.h>
  3.  
  4. typedef struct Item {
  5.     char c;
  6.     struct Item *next;
  7. } Item;
  8.  
  9. int getList (Item **);
  10. void putList(Item *);
  11. Item *deleteList(Item *);
  12.  
  13. int getList(Item **pptr)
  14. {
  15.     char buf[81], *str;
  16.     Item head = {'*', NULL };
  17.     Item *last = &head;
  18.     int n, rc = 1;
  19.     do
  20.     {
  21.         n = scanf("%80[^\n]", buf);
  22.         if(n < 0)
  23.         {
  24.             deleteList(head.next);
  25.             head.next = NULL;
  26.             rc = 0;
  27.             continue;
  28.         }
  29.  
  30.         if(n > 0)
  31.         {
  32.             for(str = buf; *str != '\0'; ++str){
  33.                 last->next = (Item *)malloc(sizeof(Item));
  34.                 last = last->next;
  35.                 last->c = *str;
  36.             }
  37.             last->next = NULL;
  38.         }
  39.         else
  40.             scanf("%*c");
  41.  
  42.     } while(n > 0);
  43.         *pptr = head.next;
  44.         return rc;
  45. }
  46.  
  47. int main()
  48. {
  49.     Item *st;
  50.  
  51.     while(puts("enter string"), getList(&st)){
  52.         putList("Entered string", st);
  53.         st = deleteList(st);
  54.     }
  55.     return 0;
  56. }
  57.  
  58. Item *reorg(Item *p)
  59. {
  60.     Item head = {'\0', p},
  61.     *last = &head, *prev = NULL;
  62.  
  63.     int f = 1;
  64.     while(last && (last->next = delSpace(last->next)) ){
  65.         if( f )
  66.             last->next = delWord(last->next);
  67.  
  68.         else{
  69.             prev = skipWord(last->next);
  70.             last = prev->next;
  71.             if( last )
  72.             last->c = ' ';
  73.         }
  74.         f = !f;
  75.     }
  76.  
  77.     if(last && prev){
  78.         prev->next = NULL;
  79.         free(last);
  80.     }
  81.  
  82.     return head.next;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement