I am trying to write this program to reverse a string. If I were to give it the string "birds and bees," it would give me bees and birds in response. This program does not work, though, and results in a segmentation fault. What is my error and how do I fix it?
char* original = (char*) malloc(80 * sizeof(char));
char temp; //same as char* temp
fgets(original, 80, stdin);
ptr = strtok(original, " ");
while(strtok(original, " \n") != NULL) //until end of line
ptr = strtok(NULL, " \n");
sprintf("%s", ptr, reverse); //THIS CAUSES THE ERROR