answersLogoWhite

0

The following code is supposed to take the characters stored in str and move those characters into buff in reverse order, but there is a coding mistake preventing this.

Find the bug.

// reverses str and puts the result in buff

// NOTE: buff must be at least as large as str

void strReverse(const int str_length, const char* str, char* buff) {

// special case for zero-length strings

if( str_length == 0 ) {return; }

// reverse

int i;

for(i = 0; i < str_length; ++i) {buff[i] = str[str_length - i]; }

buff[i] = '\0';

}

User Avatar

Wiki User

16y ago

What else can I help you with?