Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.20 KB | None | 0 0
  1. void newStrings(Item *p, Item *pptr1, Item *pptr2) {
  2.     Item head = { '*', p };
  3.     Item head_n = { '*' };
  4.     Item head_c = { '*' };
  5.     Item *last_n = &head_n;
  6.     Item *last_c = &head_c;
  7.     Item *cur = &head;
  8.     cur = cur->next;
  9.     int fl = 1;
  10.  
  11.     while (cur) {
  12.  
  13.         if (cur->c == ' ' || cur->c == '\t') {
  14.             cur = delSpace(cur);
  15.  
  16.             if (fl==1) {
  17.                 Item *buf = cur;
  18.                 cur = cur ->next;
  19.                 free(buf);
  20.                 fl = 0;
  21.                 continue;
  22.             }
  23.  
  24.             if (cur->next == NULL) {
  25.                 free(cur);
  26.                 break;
  27.             }
  28.  
  29.             last_n->next = cur;
  30.             last_n = last_n->next;
  31.  
  32.             char buf[] = { ' ', '\0' };
  33.             last_c->next = (Item *)malloc(sizeof(Item));
  34.             last_c = last_c->next;
  35.             last_c->c = *buf;
  36.             last_c->next = NULL;
  37.         }
  38.         else {
  39.             if (fl == 1)
  40.                 fl = 0;
  41.  
  42.             if (cur->c == '1' || cur->c == '2' || cur->c == '3' || cur->c == '4' || cur->c == '5' || cur->c == '6' || cur->c == '7' || cur->c == '8' || cur->c == '9' || cur->c == '0') {
  43.                 last_n->next = cur;
  44.                 last_n = last_n->next;
  45.             }
  46.             else {
  47.                 last_c->next = cur;
  48.                 last_c = last_c->next;
  49.  
  50.             }
  51.         }
  52.         cur = cur->next;
  53.     }
  54.     last_n->next = NULL;
  55.     last_c->next = NULL;
  56.  
  57.     putList("Result string1", head_n.next);
  58.     putList("Result string2", head_c.next);
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement