Advertisement
Guest User

Untitled

a guest
Apr 4th, 2012
746
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. #include <stddef.h>
  2. #include <stdint.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5.  
  6. int strrev(uint8_t* source, uint8_t* destination){
  7.     uint8_t *end, *dst;
  8.  
  9.     destination += strlen(source);
  10.  
  11.     while (*source) {
  12.         end = source;
  13.  
  14.         do {
  15.             destination--;
  16.             end++;
  17.         } while (*end && 0x80 == (*end & 0xC0));
  18.  
  19.         for (dst = destination; source < end; ++dst, ++source) {
  20.             *dst = *source;
  21.         }
  22.     }
  23. }
  24.  
  25. int main() {
  26.     char text[] = "Тест перевернутой строки!";
  27.     char result[sizeof(text)];
  28.  
  29.     result[strlen(text)] = 0;
  30.  
  31.     for (int i = 0; i<1000000; i++) {
  32.         strrev(text, result);
  33.     }
  34.  
  35.     printf("Result: %s", result);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement