hello i wrote below a program in c,
#include <stdio.h>
#include <conio.h>
void main()
{
FILE *fp;
char c;
long n=0L;
fp=fopen("myfile.txt","w");
printf("Enter the data into file:\n");
while((c=getchar())!=EOF)
{
putc(c,fp);
}
printf("Total character into file:%ld\n",ftell(fp));
fclose(fp);
fp=fopen("myfile.txt","r");
while(feof(fp)==0)
{
fseek(fp,n,0);
printf("\n char:'%c' at position '%ld'",getc(fp),ftell(fp));
n++;
}
fclose(fp);
getch();
}
it work fine but when i replace the statement:
printf("\n char:'%c' at position '%ld'",getc(fp),ftell(fp));
with the statement:
printf("\n position '%ld'",ftell(fp));
then it will going to infinite loop
I knew the function,
fseek()It set the file pointer to specified position. but here what happen,i don't understand. please help me.