fseek Questions

4

Solved

If I have a text file with the following content opened as binary 1234567890 a call like this: fseek(fp, 5L, SEEK_SET); give me 6 when I call (char)fgetc(fp) because I offset 5 byte from byt...
Starrstarred asked 18/12, 2014 at 15:11

2

Solved

while (fread(&product, sizeof(Product), 1, file) == 1) { product.price *= 2.0; fseek(file, -sizeof(Product), SEEK_CUR); fwrite(&product, sizeof(Product), 1, file); fseek(file, 0, SEEK_C...
Leeland asked 14/5, 2023 at 3:58

1

Solved

C2x, 7.21.9.2 The fseek function: Synopsis #include <stdio.h> int fseek(FILE *stream, long int offset, int whence); Why does fseek have long int offset instead of long long int offset? It ...
Chalcography asked 7/2, 2022 at 15:4

10

Solved

How do I read a file backwards line by line using fseek? code can be helpful. must be cross platform and pure php. many thanks in advance regards Jera
Knowlton asked 13/7, 2010 at 6:6

2

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_LA...
Weitzel asked 28/9, 2015 at 15:3

2

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 correspondin...
Cogen asked 4/7, 2019 at 20:36

4

Solved

I'm reading data from a file to memory that is opened with: FILE *f = fopen(path, "rb"); Before I start copying bytes from the file I seek to a start position using: /** * Goes to the given ...
Hobard asked 23/6, 2013 at 18:18

2

Solved

Does f.seek(500000,0) go through all the first 499999 characters of the file before getting to the 500000th? In other words, is f.seek(n,0) of order O(n) or O(1)?
Hadsall asked 11/8, 2018 at 15:34

2

Solved

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 posi...
Knockknee asked 13/10, 2017 at 7:23

4

Solved

Here is my code: <?php $url="http://www.sina.com.cn"; $handle = @fopen($url, "r"); $len=get_headers($url,true); print_r($len); echo $len['Content-Length']."\n"; if ($handle) { while (($b...
Briolette asked 24/12, 2015 at 2:16

2

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, ...
Presser asked 14/8, 2015 at 17:48

2

Solved

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 ...
Dusa asked 27/4, 2015 at 15:10

1

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 ...
Trierarch asked 29/6, 2014 at 1:18

1

Solved

The C spec has an interesting footnote (#268 C11dr §7.21.3 9) "Setting the file position indicator to end-of-file, as with fseek(file, 0, SEEK_END), has undefined behavior for a binary stream (b...
Sulfur asked 10/1, 2014 at 17:27

2

Solved

I'm trying to append the contents of a file myfile.txt to the end of a second file myfile2.txt in c. I can copy the contents, but I can't find a way to append. Here's my code: FILE *pFile; FILE *p...
Cop asked 17/10, 2013 at 14:13

2

Solved

I have noticed two methods to return to the beginning of a file FILE *fp = fopen("test.bin", "r") fseek(fp, 0, SEEK_END); rewind(fp); and FILE *fp = fopen("test.bin", "r") fseek(fp, 0, SEEK_EN...
Commotion asked 7/8, 2012 at 3:54

2

Solved

offset=ftell(ptr)-sizeof(student1); fseek(ptr,offset,SEEK_SET); fwrite(&student1,sizeof(student1),1,ptr); This C code means move the pointer from the current position ftell(ptr) to start of t...
Gusti asked 11/11, 2012 at 10:52

5

Solved

I've read posts that show how to use fseek and ftell to determine the size of a file. FILE *fp; long file_size; char *buffer; fp = fopen("foo.bin", "r"); if (NULL == fp) { /* Handle Error */ } ...
Embankment asked 11/5, 2011 at 0:9

1

Solved

What is the difference between ftello/fseeko and fgetpos/fsetpos? Both seem to be file pointer getting/setting functions that use opaque offset types to sometimes allow 64 bit offsets. Are they sup...
Redfish asked 25/8, 2012 at 4:23

3

Solved

I have a file of about 2000 lines of text that i generate in my program, every line has the information of an employee and it's outputed like this 1 1 Isaac Fonseca 58 c 1600 1310.40 6 1 0.22 21...
Picasso asked 14/7, 2012 at 22:31

4

Solved

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(...
Janettejaneva asked 23/5, 2012 at 0:47

1

Solved

FILE* f = fopen("rajat", "w"); fputs("sometext", f); fseek(f, 6, SEEK_SET); fputs("is a", f); fclose(f); Successfully returns: "someteis a" But FILE* f = fopen("rajat", "a"); fputs("sometext", ...
Ruvolo asked 17/5, 2012 at 7:56

3

Solved

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 t...
Abbate asked 25/3, 2012 at 18:25

4

Solved

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 = ...
Notation asked 3/2, 2012 at 20:46

2

Solved

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 ...
Cully asked 27/4, 2011 at 15:22

© 2022 - 2024 — McMap. All rights reserved.