Advertisement
delneg

Untitled

Apr 17th, 2014
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.35 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <locale.h>
  3. #include <stdlib.h>
  4. typedef struct list
  5. {
  6.     char info;
  7.     struct list *next;
  8. } list;
  9. list* deletelist(list *pt);
  10. int getlist(list **pt);
  11. void putlist(char *msg,list *pt);
  12.  
  13. int main(int argc, const char * argv[])
  14. {
  15.    
  16.     list *st;
  17.    
  18.     while (puts("Введите строку:"),getlist(&st)){
  19.         putlist("Исходная строка: \n", st);
  20.         st = reorg(st);
  21.         putlist("Преобразованная строка: \n", st);
  22.         st = deletelist(st);
  23.     }
  24.     puts("That's all. Bye!");
  25.     return 0;
  26. }
  27.  
  28.  
  29.  
  30.  
  31. list* deletelist(list *pt)
  32. {
  33.     list *p=NULL;
  34.     while (pt!=NULL)
  35.     {
  36.         p=pt;
  37.         pt=pt->next;
  38.         free(p);
  39.     }
  40.     return pt;
  41. }
  42. int getlist(list **pt)
  43. {
  44.     char buf[81];
  45.     int i,n, flag=1;
  46.     list head={'*',NULL};
  47.     list *last=&head;
  48.     do
  49.     {
  50.         n=scanf("%80[^\n]",buf);
  51.         if (n<0)
  52.         {
  53.             flag=0;
  54.             head.next=deletelist(head.next);
  55.             continue;
  56.         }
  57.         if (n==0)
  58.         {
  59.             scanf("%*c");
  60.         }
  61.         else
  62.         {
  63.             for(i=0;buf[i]!='\0';++i)
  64.             {
  65.                 last->next=(list*) malloc(sizeof(list));
  66.                 last=last->next;
  67.                 last->info=buf[i];
  68.                 last->next=NULL;
  69.             }
  70.         }
  71.        
  72.     }
  73.     while (n>0);
  74.     *pt=head.next;
  75.     return flag;
  76. }
  77. void putlist(char *msg,list *pt)
  78. {
  79.     printf("%s \"",msg);
  80.     while (pt!=NULL)
  81.     {
  82.         printf("%c",pt->info);
  83.         pt=pt->next;
  84.     }
  85.     printf("\"\n");
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement