Questions tagged [fseek]

fseek is a C function belonging to the ANSI C standard library, and included in stdio.h. Its purpose is to change the file position indicator for the specified file or stream.

fseek() is a C function belonging to the ANSI C standard library, and included in the file stdio.h. Its purpose is to change the file position indicator for the specified file or stream. Because fseek uses 32 bit values on many platforms it has a limitation of maximum 2 gigabyte seeks. fseeko64 would be used for larger offsets.

See also

419 questions
10
votes
2 answers

How in portable C to seek forward when reading from a pipe

Since fseek() does not work on pipes what methods exist for simulating seeking forward? The naive approach is to use fread() and throw away the contents read into the memory buffer. For huge seeks to avoid huge buffers you would use the same buffer…
hippietrail
  • 15,848
  • 18
  • 99
  • 158
8
votes
3 answers

Go to a certain point of a binary file in C (using fseek) and then reading from that location (using fread)

I am wondering if this is the best way to go about solving my problem. I know the values for particular offsets of a binary file where the information I want is held...What I want to do is jump to the offsets and then read a certain amount of…
user1291631
  • 83
  • 1
  • 1
  • 4
8
votes
2 answers

fseek passing negative offset and SEEK_CUR

I have a bad performance running fseek(..) in a very big file. Every time a call fseek function, I need to move the file pointer position backward 100 bytes: fseek(fp, -100, SEEK_CUR); before, I was doing this: fseek(fp, (index)*100, SEEK_SET);…
ATL
  • 99
  • 1
  • 1
  • 3
8
votes
6 answers

Determining the size of a file larger than 4GB

The code currently does this and the fgetpos does handle files larger than 4GB but the seek returns an error, so any idea how to seek to the end of a file > 4GB? fpos_t currentpos; sok=fseek(fp,0,SEEK_END); assert(sok==0,"Seek…
KPexEA
  • 16,560
  • 16
  • 61
  • 78
7
votes
2 answers

Seek on a large text file python

I have a few text files whose sizes range between 5 gigs and 50 gigs. I am using Python to read them. I have specific anchors in terms of byte offsets, to which I can seek and read the corresponding data from each of these files (using Python's file…
khan
  • 7,005
  • 15
  • 48
  • 70
7
votes
1 answer

Can fseek(stdin,1,SEEK_SET) or rewind(stdin) be used to flush the input buffer instead of non-portable fflush(stdin)?

Since I discovered fflush(stdin) is not a portable way to deal with the familiar problem of "newline lurking in the input buffer",I have been using the following when I have to use scanf: while((c = getchar()) != '\n' && c != EOF); But today I…
Jugni
  • 255
  • 5
  • 12
6
votes
1 answer

Why does fseek have "long int offset" instead of "long long int offset"?

C2x, 7.21.9.2 The fseek function: Synopsis #include int fseek(FILE *stream, long int offset, int whence); Why does fseek have long int offset instead of long long int offset? It seems that on operating systems with data model LLP64 or…
pmor
  • 5,392
  • 4
  • 17
  • 36
6
votes
2 answers

Troubles with fseek() and reading from file

I have started learning C (via Youtube and K&R) some time ago and I am trying to write some programs as practice. Currently I want to create a program that reads words from a file and compares the beginning of it with the input from the user. The…
Milan Todorovic
  • 155
  • 1
  • 8
6
votes
1 answer

Quick-fixing 32-bit (2GB limited) fseek/ftell on freebsd 7

I have old 32-bit C/C++ program on FreeBSD, which is used remotely by hundreds of users, and author of which will not fix it. It was written in unsafe way, all file offset are stored internally as unsigned 32-bit offsets, and ftell/fseek functions…
osgx
  • 90,338
  • 53
  • 357
  • 513
6
votes
4 answers

PHP: Read from certain point in file

Similar to: How to read only 5 last line of the text file in PHP? I have a large log file and I want to be able to show 100 lines from position X in the file. I need to use fseek rather than file() because the log file is too large. I have a similar…
dukevin
  • 22,384
  • 36
  • 82
  • 111
5
votes
4 answers

Are there cases where fseek/ftell can give the wrong file size?

In C or C++, the following can be used to return a file size: const unsigned long long at_beg = (unsigned long long) ftell(filePtr); fseek(filePtr, 0, SEEK_END); const unsigned long long at_end = (unsigned long long) ftell(filePtr); const unsigned…
Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
5
votes
5 answers

Using fseek to backtrack

Is using fseek to backtrack character fscanf operations reliable? Like for example if I have just fscanf-ed 10 characters but I would like to backtrack the 10 chars can I just fseek(infile, -10, SEEK_CUR) ? For most situations it works but I seem…
Yew Long
  • 609
  • 2
  • 9
  • 15
5
votes
2 answers

byte position: file_get_contents vs fopen

I need some data from a specific byte in range in a binary file. (concatenated jpegs, don't ask...) So I have a offset and length data from an external API. (I would guess that those are byte positions) What works is the following: $fileData =…
gherkins
  • 14,603
  • 6
  • 44
  • 70
5
votes
2 answers

ftello() and fseeko() android build errors

I am trying to build Android L for 64-bit architecture. My code goes like: #if (HAS_LARGE_FILE_SUPPORT) #define _FILE_OFFSET_BITS 64 //Defined in header file /*Some File operations*/ #if HAS_LARGE_FILE_SUPPORT return fseeko(iFile, offset,…
5
votes
1 answer

About PHP's fseek() method, what exactly offset (position) is?

Perhaps its my english but the explanation in the PHP Manual (quoted bellow) doesn't answer my question quite clearly. To move to a position before the end-of-file, you need to pass a negative value in offset and set whence to SEEK_END. I have a…
Ali
  • 2,993
  • 3
  • 19
  • 42
1
2
3
27 28