Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. void reverse(char *s) {
  6. for (char *front = s, *back=s+strlen(s)-1; front < back; *front ^= *back, *back ^= *front, *front ^= *back, ++front, --back) {}
  7. }
  8.  
  9. void test(const char* s) {
  10. char* tmp = strdup(s);
  11. printf("before: %s\n", tmp);
  12. reverse(tmp);
  13. printf("after: %s\n\n", tmp);
  14. free(tmp);
  15. }
  16.  
  17. int main(int argc, char** argv) {
  18. test("hello, dingus");
  19. test("hello, dingus!");
  20. test("");
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement