You better of copying string to some other temp string.
- Use another
char*
to copy original string. Allocate sufficient memory. - Copy sources string to this one. Don't forget to null terminate it.
- reverse..
- Dont forget to free this memory after use.
char *a1 = "Hello"; char* copy_a1 = malloc(sizeof(char)*(strlen(a1)+1)); strncpy(copy_a1, a1, strlen(a1)); copy_a1[strlen(a1)] = '\0'; reverse(copy_a1); //free memory used.