Questions tagged [fgetpos]

The C library function fgetpos() gets the current file position information.

14 questions
14
votes
1 answer

ftello/fseeko vs fgetpos/fsetpos

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 supported on different platforms or by different…
Jeremy Salwen
  • 8,061
  • 5
  • 50
  • 73
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
3 answers

Reading and writing to a file at the same time in C

Supposed to swap every two lines in a file until just one line remains or all lines are exhausted. I don't want to use another file in doing so. Here's my code: #include int main() { FILE *fp = fopen("this.txt", "r+"); int i = 0; …
ps_
  • 97
  • 2
  • 12
3
votes
3 answers

Are fgetpos() and fsetpos() only for text mode? What location/offset data is the fpos_t object filled with if not number of bytes?

I understand the workings of ftell() and fseek() in C, but for this question I couldn't find any precise answer anywhere, including from the closest post on StackOverflow(LINK). So can you please answer the following: Can it be concluded that…
Meathead
  • 493
  • 2
  • 6
  • 15
2
votes
1 answer

Is fgetpos/fsetpos any faster than fseek?

I know fgetpos/fsetpos are used for returning to a file position. But if I accessed that position with fseek to begin with, is it more efficient to use fgetpos/fsetpos to return later, or just the same fseek again?
Jespoke
  • 99
  • 4
2
votes
2 answers

c++ fread changing fgetpos strangely

If I run: FILE* pFile = fopen("c:\\08.bin", "r"); fpos_t pos; char buf[5000]; int ret = fread(&buf, 1, 9, pFile); fgetpos(pFile, &pos); I get ret = 9 and pos = 9. However if I run FILE* pFile = fopen("c:\\08.bin", "r"); fpos_t pos; char…
Steve
  • 4,859
  • 5
  • 21
  • 17
0
votes
0 answers

Clarification in using fsetpos() in text file

I'm trying to implement an evaluation of the arithmetic expression algorithm for my exam in C. I have a text file with the expression e.g "12 - 2 + cos(8)" in "r" mode. In "while" cycle I read 1 character and then apply switch on it. When I need to…
kostuyk21
  • 5
  • 2
0
votes
5 answers

c fgetpos giving wrong position

I am new to C and I have this code: f = fopen( argv[1], "rb" ); fseek( f, 64, SEEK_SET ); fpos_t pos; fgetpos (f, &pos); printf("%x", pos); However, this returns 40, even though it's supposed to be returning 64. What am i doing wrong?
GManz
  • 1,548
  • 2
  • 21
  • 42
0
votes
1 answer

`fgetpos` Not Returning the Correct Position

Update: To get around the problem below, I have done if (ftell(m_pFile) != m_strLine.size()) fseek(m_pFile, m_strLine.size(), SEEK_SET); fpos_t position; fgetpos(m_pFile, &position); this then returns the correct position for my file. However,…
MoonKnight
  • 23,214
  • 40
  • 145
  • 277
0
votes
1 answer

fgetpos failing in iOS 6.1 simulator when opening files in bundles

I'm working on some multiplatform C++ code. Hence the requirement to use fopen, fgetpos, etc. The following was working earlier on iOS and with my update to the latest version it stopped working. I have a couple of text files Shader.vsh and…
Shammi
  • 492
  • 5
  • 13
0
votes
1 answer

skipping first half of a 59GB fastq file to process last half: read line-by-line, or fgetpos?

I have 2 ~59GB text files in ".fastq" format. fastq files are genomics read files from a sequencer. Every 4 lines is a new read, but the lines are of variable size. The filesize is roughly 59GB, and there are about 211M reads-- which means, give…
HodorTheCoder
  • 254
  • 2
  • 11
-1
votes
2 answers

where to overwrite get_posts methods in single posts page

we are having a performance issue for it we need to customize the calling of methods $get_posts methods in main post single page but we can't find where does it's code located we want to overwrite the $q['fields'] array in this part switch (…
Miroo
  • 795
  • 3
  • 13
  • 35
-2
votes
3 answers

Write in a specific line in html from php

I'm new to php. The thing I'm trying to accomplish here is to see what is the number of the last line in my html document (1,2,3...) and put that value into a variable and write Hello world to the html document but 2 or 3 lines above the last…
Leon Kunštek
  • 555
  • 1
  • 7
  • 21
-5
votes
1 answer

fsetpos does not set the file pointer's position as expected

//This is an *abstract* from my code: FILE* fpointer; fpos_t pos1,pos2; // make a do-while loop do{ // I am reading a text file word by word c = fscanf(fpointer, "%s", temp); /* a code *begins* here. I am doing parsing stuff stuff …
Gold_Sky
  • 103
  • 4