I try to reverse string but the function ReverseString() does not work using the second call. Why is that?
void ReverseString(char *c)
{
int length = strlen(c);
char *front = c;
char *end = c + length - 1;
char ftemp = NULL;
char etemp = NULL;
while (end >= front)
{
ftemp = *front;
etemp = *end;
*front = etemp;
*end = ftemp;
front++;
end--;
}
cout<<c;
}
int _tmain(int argc, _TCHAR* argv[])
{
char sentence[] = "hello world";
ReverseString(sentence, reverseStr2);//first call and this works
ReverseString("hello world", reverseStr2);//second call, but does not work
return 0;
}

New Topic/Question
Reply




MultiQuote




|