0

after two or more weeks I have finished recover problem set - the longest issue was with the cursor and debugging.

I less than more know how to use debug50 but if somebody could tell me how can I keep track where is currently the cursor in my running programe?

0

according to the description of ftell:

The C library function long int ftell(FILE *stream) returns the current file position of the given stream.

stream − This is the pointer to a FILE object that identifies the stream.

When we say that it returns the current position in the file, it is the number of bytes from the beginning to a given point, it is usually used with fseek (), which places the course at a known point, in the following example the program returns the number of bytes up to the end of the file:

#include <stdio.h>

int main (void)
{
   FILE *fp = NULL;
   int len = 0;

   fp = fopen("file.txt", "r");
   if( fp == NULL )  {
      perror ("Error opening file");
      return(-1);
   }
   fseek(fp, 0, SEEK_END);

   len = ftell(fp);
   fclose(fp);

   printf("Total size of file.txt = %d bytes\n", len);

   return(0);
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .