Guest User

Untitled

a guest
Nov 24th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. // ackit -reverse strings
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. char house[]=" t his is a test string";
  7. //string test a is his t //
  8.  
  9.  
  10.  
  11. int main(){
  12.  
  13. int len = strlen(house);
  14.  
  15. char *buff = (char*)malloc(len+1);
  16. memset(buff,'\0',len * sizeof(char)+1);
  17.  
  18. char* end = (house+len);
  19. char* beg = end;
  20.  
  21. int j = 0;
  22. for(int i = 0; i < len+1; i++){
  23. beg--;
  24. if(*beg == ' ' || beg < house){
  25.  
  26. char* tmp = beg;
  27. tmp++;
  28. while(tmp != end){
  29. buff[j++] = *tmp++;
  30. }
  31.  
  32. buff[j++]=' ';
  33. end = beg;
  34. }
  35. }
  36. buff[len+1]='\0';
  37.  
  38. printf("%s\n",buff);
  39.  
  40. return 0;
  41.  
  42. }
Add Comment
Please, Sign In to add comment