In the last while loop, every 5th character stored in the file should be printed, but the loop is going on indefinitely and not terminating. the feof() function should return 1 on reaching END OF FILE and the loop should be exited but the loop is going on indefinitely.
#include<stdio.h>
main() {
long n, k;
char c;
FILE *fp;
fp = fopen("RANDOM", "w");
while ((c = getchar()) != EOF) {
putc(c, fp);
}
n = ftell(fp);
printf("\nNo. of characters entered by the user is : %ld\n", n);
fclose(fp);
fp = fopen("RANDOM", "r");
while(feof(fp) == 0) {
n = ftell(fp);
c = getc(fp);
printf("The character at %ld position is %c\n", n, c);
fseek(fp, 4l, 1);
}
}