Advertisement
Guest User

Untitled

a guest
Sep 9th, 2021
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.39 KB | None | 0 0
  1. void strtrim(char *str){
  2.     char *begin = NULL, *end = NULL, *c;
  3.     int at_space_substr = 1;
  4.     for(c = str; *c; c++){
  5.         if((*c == ' ' || *c == '\t') ^ at_space_substr){
  6.             if(!begin)
  7.                 begin = c;
  8.             else if(!at_space_substr)
  9.                 end = c;
  10.             at_space_substr ^= 1;
  11.         }
  12.     }
  13.     if(!begin)
  14.         goto ret;
  15.     if(!end)
  16.         end = c;
  17.     for(c = begin; c < end; c++, str++)
  18.         *str = *c;
  19. ret:
  20.     *str = '\0';
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement