Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Interview with Charlton
- in = “This is a nvidia building”
- Out = “building nvidia a is This”
- char * reverse( char * in ) {
- char * Out = (char *) malloc( sizeof( char ) * strlen( in ) );
- char * buf = (char *) malloc( sizeof( char ) * strlen( in ) );
- int wordlen = 0, outlen = 0, initialStrLen = strlen( in );
- Out[0] = ‘\0’
- for (int i = 0; i < initialStrLen; ++i) {
- if (in[i] = ‘ ‘) {
- in[i] = ‘\0’;
- buf[0] = ‘\0’;
- strcat(buf, in + (i - wordlen)); //buf = This\0
- strcat(buf, “ “); //buf = This \0
- strcat(buf, Out); //buf = is This \0
- strcpy(Out, buf); //Out = This \0
- Outlen += wordlen + 1 //outlen = 5
- wordlen = 0;
- }
- else {
- wordlen++;
- }
- }
- Out[outlen - 1] = ‘\0’
- free(buf);
- return Out
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement