Pointers

closed account (98qiz8AR)
Can anybody show me how to use pointers in this function of my code?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

void Name::ReverseUsingPtrs(char *Reversed)
{
    string temp_array = TheName;
    unsigned i = 0;
    while (TheName[i++] != ' ')
        ;
    unsigned j=0;
    while (TheName[i] != '\0')
        Reversed[j++] = TheName[i++];
    Reversed[j++] = ',';
    Reversed[j++] = ' ';
    
    i = 0;
    while (TheName[i] != ' ')
        Reversed[j++] = TheName[i++];
    Reversed[j] = '\0';

}
Your code assumes the string passed in has at least one space.

It's not clear why you have temp_array in that function.

Do you know what a pointer is, how a array is passed to function and the relationship between pointers and arrays? It might be better to help you with that stuff rather than focusing on this particular function.

It's better to learn to fish than to be given a fish.
Topic archived. No new replies allowed.