[Solved] how to reverse a string using array of pointers?


I am not sure what you are asking, But the following program meets your conditions,
1. there is array of pointers
2. there is malloc
3. there is no character array

#include <stdio.h>
#include <stdlib.h>

#define STR_MAX_SIZE 256

int main()
{
    char *str;
    char *pos[2];
    char c;

    if((str = malloc(STR_MAX_SIZE)) ==NULL) {
        return -1;
    }
    scanf("%s",str);

    pos[0] = str;
    pos[1] = str;
    while(*pos[1]) {
        pos[1]++;
    }
    pos[1] -= 1;

    while(pos[0] < pos[1]) {
        c = *pos[0];
        *pos[0] = *pos[1];
        *pos[1] = c;
        pos[0]++;
        pos[1]--;
    }
    printf("reversed : %s\n",str);
    return 0;
}

2

solved how to reverse a string using array of pointers?