Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <locale.h>
- #include <stdlib.h>
- typedef struct list
- {
- char info;
- struct list *next;
- } list;
- list* deletelist(list *pt);
- int getlist(list **pt);
- void putlist(char *msg,list *pt);
- int main(int argc, const char * argv[])
- {
- list *st;
- while (puts("Введите строку:"),getlist(&st)){
- putlist("Исходная строка: \n", st);
- st = reorg(st);
- putlist("Преобразованная строка: \n", st);
- st = deletelist(st);
- }
- puts("That's all. Bye!");
- return 0;
- }
- list* deletelist(list *pt)
- {
- list *p=NULL;
- while (pt!=NULL)
- {
- p=pt;
- pt=pt->next;
- free(p);
- }
- return pt;
- }
- int getlist(list **pt)
- {
- char buf[81];
- int i,n, flag=1;
- list head={'*',NULL};
- list *last=&head;
- do
- {
- n=scanf("%80[^\n]",buf);
- if (n<0)
- {
- flag=0;
- head.next=deletelist(head.next);
- continue;
- }
- if (n==0)
- {
- scanf("%*c");
- }
- else
- {
- for(i=0;buf[i]!='\0';++i)
- {
- last->next=(list*) malloc(sizeof(list));
- last=last->next;
- last->info=buf[i];
- last->next=NULL;
- }
- }
- }
- while (n>0);
- *pt=head.next;
- return flag;
- }
- void putlist(char *msg,list *pt)
- {
- printf("%s \"",msg);
- while (pt!=NULL)
- {
- printf("%c",pt->info);
- pt=pt->next;
- }
- printf("\"\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement