Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <malloc.h>
- typedef struct Item {
- char c;
- struct Item *next;
- } Item;
- int getList (Item **);
- void putList(Item *);
- Item *deleteList(Item *);
- int getList(Item **pptr)
- {
- char buf[81], *str;
- Item head = {'*', NULL };
- Item *last = &head;
- int n, rc = 1;
- do
- {
- n = scanf("%80[^\n]", buf);
- if(n < 0)
- {
- deleteList(head.next);
- head.next = NULL;
- rc = 0;
- continue;
- }
- if(n > 0)
- {
- for(str = buf; *str != '\0'; ++str){
- last->next = (Item *)malloc(sizeof(Item));
- last = last->next;
- last->c = *str;
- }
- last->next = NULL;
- }
- else
- scanf("%*c");
- } while(n > 0);
- *pptr = head.next;
- return rc;
- }
- int main()
- {
- Item *st;
- while(puts("enter string"), getList(&st)){
- putList("Entered string", st);
- st = deleteList(st);
- }
- return 0;
- }
- Item *reorg(Item *p)
- {
- Item head = {'\0', p},
- *last = &head, *prev = NULL;
- int f = 1;
- while(last && (last->next = delSpace(last->next)) ){
- if( f )
- last->next = delWord(last->next);
- else{
- prev = skipWord(last->next);
- last = prev->next;
- if( last )
- last->c = ' ';
- }
- f = !f;
- }
- if(last && prev){
- prev->next = NULL;
- free(last);
- }
- return head.next;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement