You forgot to add null termination to
switched
. You need to addswitched[counter] = '\0'; // add '\0' to the end
before
printf("Your flipped text is: %s \n", switched);
You need to change
while(*ptrword != NULL)
towhile(*ptrword != '\0')
.As @ooga pointed out, you'd better allocate enough space to
flipped
. So changechar flipped[] = "";
tochar flipped[100] = "";
.
After fixing these issues, it should work as expected. Check out running result on Ideone.