Hi...this code dun have compilation error but got some runtime error..when i try to reverse by word..it can't read to next word for example [ This is reverse] Output : [siht is reverse]Code:char *reverseWord(char* text){ int i, j, c; char *ptr; char temp[STRING]; int stringLength; stringLength = strlen(text); ptr = text; strcpy(temp, text); for (i=0, j=stringLength-1; j > i; i++, j--) { c = text[i]; text[i] = text[j]; text[j] = c; } return ptr; } void reverse() { int i, j; int c; char text[STRING + 1]; char outputString[STRING + 1]; char *tokenPtr; char temp[STRING + 1]; int stringLength; int *counter; countOption(2, counter); stringLength = strlen(text); get_input(text); strcpy(outputString, text); tokenPtr = strtok(text, " "); tokenPtr = reverseWord(tokenPtr); strcpy(temp, tokenPtr); while ((tokenPtr = strtok(NULL, " ")) != NULL) { tokenPtr = reverseWord(tokenPtr); strcat(temp, tokenPtr); } j = 0; for (i = 0; i < stringLength; i++) { outputString[i] = temp[j]; j++; } printf("Reverse String %s\n", outputString); }
What is my problem??Can anyone help me..Please i will appreciate everythings if you help me..Thanks..