decimal

Pages: 12
can anyone help me to understand these statements please?

1
2
3
4
5
6
7
8
9
10
11
for (char *ptr = result; *ptr; ptr++)
            length++;
         //copy result to a temporary string
         char *temp = new char[length + 1];
         for (char *ptr = result, *tempPtr = temp; *ptr; ptr++, tempPtr++)
            *tempPtr = *ptr;
         //copy back to result in reversed order
         for (int i = length - 1; i >= 0; i--)
            result[length - 1 - i] = temp[i];
         //free memory of the temporary string
         delete [] tem

?
The comments pretty much say it all? It's a really cumbersome way to reverse a c string.

The first loop determines the length of the string.
The second loop copies the string to a temporary buffer.
The third loop copies the temporary buffer in reverse order to the result buffer.
Topic archived. No new replies allowed.
Pages: 12