Heres the problem i have: Write a program that reads in a line of input and then prints the line out in reverse order. Recall that you can use scanf() with the %c specifier to read one character at a time from input and that the newline character (\n) is generated when you press the Enter key.
this is the code i have but it doesnt work. what am i doin wrong. Any help would be greatly appreciated.
Code:#include <stdio.h> #include <string.h> int main(void) { char ch[255]; int index, n, i; for (index = 0; ch[index] != '\n'; index++) { scanf("%c", &ch[index]); } n = strlen(ch); for (i = n - 1; i >= 0; i--) { printf("%c", ch[i]); } system ("pause"); return 0; }



Reply With Quote