Guest User

Untitled

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