| |

VerySource

 Forgot password?
 Register
Search
View: 1108|Reply: 8

How to use fseek?

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-3-16 18:00:01
| Show all posts |Read mode
How to use fseek?
Using fseek (fp, 1000,1,0);
Why do I keep getting errors?
Can't FSEEK be used under VC?
Thank you!
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-6-17 19:15:01
| Show all posts
How can fseek have four parameters?
Reply

Use magic Report

0

Threads

9

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-6-17 23:30:01
| Show all posts
int fseek( FILE *stream, long offset, int origin );

Example

/* FSEEK.C: This program opens the file FSEEK.OUT and
* moves the pointer to the file's beginning.
*/

#include <stdio.h>

void main( void)
{
   FILE *stream;
   char line[81];
   int result;

   stream = fopen( "fseek.out", "w+" );
   if( stream == NULL)
      printf( "The file fseek.out was not opened\n" );
   else
   {
      fprintf( stream, "The fseek begins here: "
                       "This is the file'fseek.out'.\n" );
      result = fseek( stream, 23L, SEEK_SET);
      if( result)
         perror( "Fseek failed" );
      else
      {
         printf( "File pointer is set to middle of first line.\n" );
         fgets( line, 80, stream );
         printf( "%s", line );

      }
      fclose( stream );
   }
}
Reply

Use magic Report

0

Threads

63

Posts

43.00

Credits

Newbie

Rank: 1

Credits
43.00

 China

Post time: 2020-6-23 05:15:01
| Show all posts
man fseek
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-6-24 15:45:01
| Show all posts
int fseek( FILE *stream, long offset, int origin );

origin=0 first file
origin=1 current location
origin=2 end of file

offset is the number of origin bytes in distance
Reply

Use magic Report

0

Threads

24

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-7-1 09:15:01
| Show all posts
You should install msdn
Reply

Use magic Report

0

Threads

24

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-7-1 09:45:01
| Show all posts
linux directly man is ok
Reply

Use magic Report

0

Threads

78

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-8-2 18:30:02
| Show all posts
Function name: fseek
Function: Relocate the file pointer on the stream
Usage: int fseek(FILE *stream, long offset, int fromwhere);
Program example:

#include <stdio.h>

long filesize(FILE *stream);

int main(void)
{
   FILE *stream;

   stream = fopen("MYFILE.TXT", "w+");
   fprintf(stream, "This is a test");
   printf("Filesize of MYFILE.TXT is %ld bytes\n", filesize(stream));
   fclose(stream);
   return 0;
}

long filesize(FILE *stream)
{
   long curpos, length;

   curpos = ftell(stream);
   fseek(stream, 0L, SEEK_END);
   length = ftell(stream);
   fseek(stream, curpos, SEEK_SET);
   return length;
}
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-28 09:15:01
| Show all posts
fseek parameter error, usage:
  #include"stdio.h"
  fseek (file type pointer fp, displacement, starting point);
among them:

Starting point The corresponding number The file position

SEEK_SET 0 beginning of file
To

SEEK_CUR 1 Current location of the file
To

SEEK_END 2 End of file
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list