I've written a code which is supposed to take the input from the user, save it in a file called "name" and then print it in the reverse order. But its getting stuck in an infinite loop, printing only the last character typed. The logic of the program is that, the getc(fp) in putchar(getc(fp)) will return a character and advance the file pointer by 1. The putchar will print the character and the condition in the while loop will bring the cursor back 2 places so that the next charcter can be printed...
FILE *fp;int n;
printf("\nUnable to open\n");
printf("\nNo. of characters = %ld\n",ftell(fp));
printf("Position of %c is %ld\n",getc(fp),ftell(fp));