Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the code for the function in the prototype: int StrReverse(char *array1);

ID: 3744808 • Letter: W

Question

Write the code for the function in the prototype: int StrReverse(char *array1);

The function reverses the contents of the string, and returns the length of the array. You may use NOT use strlen() or any other string library functions to implement StrReverse(), and it must work for any string length. DO NOT write main(), do not print anything.

If StrReverse() is called with this argument:

char a[] = "0123456789"; // the string.

After StrReverse() returns, the string should contain:

a = "9876543210"

and the returned value should be 10.

Explanation / Answer

ANSWER:-

// reverse function in C++

int StrReverse(char *array1)

{

int i=0,len=0;
while((array1[i])!='')
{
len++;
i++;
}
char* start = array1;
char* end=array1 + len-1;
while(start<end)
{
char temp=*start;
*start=*end;
*end= temp;
start++;
end--;
}
return len;

}

// if any doubt please comment