xotohop

строки_2

May 8th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4.  
  5. char * order_string(char * s)
  6. {
  7.     char * head = s, * tail = s + strlen(s) - 1;
  8.     while (head < tail)
  9.     {
  10.         if ( ! isdigit(*head) )
  11.             ++head;
  12.         else {
  13.             char tmp = *head;
  14.             memmove(head, head + 1, tail - head);
  15.             *tail-- = tmp;
  16.         }
  17.     }
  18.     return s;
  19. }
  20.  
  21. int main()
  22. {
  23.     char s_in[] = "ad2e57b6";
  24.     printf("IN string:  %s\n", s_in);
  25.     printf("OUT string: %s\n", order_string(s_in));
  26.     return 0;
  27. }
Add Comment
Please, Sign In to add comment