Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. Interview with Charlton
  2.  
  3. in = “This is a nvidia building”
  4. Out = “building nvidia a is This”
  5.  
  6. char * reverse( char * in ) {
  7. char * Out = (char *) malloc( sizeof( char ) * strlen( in ) );
  8. char * buf = (char *) malloc( sizeof( char ) * strlen( in ) );
  9. int wordlen = 0, outlen = 0, initialStrLen = strlen( in );
  10.  
  11. Out[0] = ‘\0’
  12. for (int i = 0; i < initialStrLen; ++i) {
  13. if (in[i] = ‘ ‘) {
  14. in[i] = ‘\0’;
  15. buf[0] = ‘\0’;
  16. strcat(buf, in + (i - wordlen)); //buf = This\0
  17. strcat(buf, “ “); //buf = This \0
  18. strcat(buf, Out); //buf = is This \0
  19. strcpy(Out, buf); //Out = This \0
  20. Outlen += wordlen + 1 //outlen = 5
  21. wordlen = 0;
  22. }
  23. else {
  24. wordlen++;
  25. }
  26.  
  27. }
  28.  
  29. Out[outlen - 1] = ‘\0’
  30. free(buf);
  31. return Out
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement