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
-1
votes
1 answer

fseek and fgets in C programming not used correctly here?

char * file = malloc(buffer); assert(file != 0); char str[20]; snprintf(file, buffer, "%s/%s", newestDirName, fileInDir->d_name); FILE * input = fopen(file, "r"); // read fseek(input, 0, SEEK_END); fgets(str, 20, input); printf("str = %s \n",…
-1
votes
2 answers

Really weird segmentation fault after rewinding file

So I open a file, go to the end to see how long it is, and then going back to the beginning causes a segmentation fault (core dumped). What the gosh? ... FILE *passkey; passkey = fopen("pass.key", "r+"); fseek(passkey, 0, SEEK_END); filesize =…
-1
votes
1 answer

go back some lines in text file C programming

I have a problem with that going back in cursor's position by a few Lines I've tested fseek(fp, -127, -4// back four lines) - but it didn't work could you help me please.
Mehdi Mk
  • 1
  • 1
-1
votes
1 answer

How can I read and obtain separated data from a file using 'fread' in C?

I've written in a file (using 'fwrite()') the…
wj127
  • 118
  • 1
  • 12
-1
votes
1 answer

Is it possible to check, if a file is empty, without fseek() and without systemcalls?

Basically just the title. I am trying to check wether or not a file is emtpy. The problem is, that this file will get absolutely massive (~1GB+) over the course of a few days, and i feel like fseek(fp,0,SEEK_END); if(ftell(fp)==0){//init…
PlatinTato
  • 378
  • 2
  • 19
-1
votes
1 answer

Why this code doesn't update file?

this program create a file,write on the file, after read from that file, update data and then put the file's content into an array. When I run the code, it doesn't work right, in fact, all values printed except for Vet[i].squadra are zero. I…
Malgiolio
  • 3
  • 1
-1
votes
2 answers

performance of fseeko(FILE* stream, off_t offset, int whence)

MY QUESTION: I've got a file that's about 4GB in size. I've never used fseeko/ftello, and I'm not too familiar with how files are organized on a disk. If I open a file and then ask fseeko to jump to, say, the 2,348,973,408th byte of the file,…
Matthew Busche
  • 551
  • 4
  • 12
-1
votes
1 answer

Using fseek and fwrite to overwrite a line in a file

I have a text file where each line is terminated by a "\n". Like so 0000 0000 0000 0000 Now, a file initially starts like above but a line can be overwritten with another line of variable length. I am using fseek() in order to set the position…
J.C.
  • 23
  • 2
  • 5
-1
votes
2 answers

fseek creates infinite loop at run time

WHAT THE CODE DOES: I read a binary file and sort it. I use a frequency array in order to do so. UPDATES:it does do the loop, but it doesn`t write the numbers correctly... That is the code. I want to write on file after reading from it. I will…
Lulu
  • 175
  • 1
  • 2
  • 12
-1
votes
2 answers

"fastfwd" file that can be pipe/socket/fifo

My function gets a FILE* to read from, and it needs to read starting from some non-negative offset. I could use fseek(file, offset, SEEK_SET), but it fails on stdin, for instance. How can I determine if fseek works? If it doesn't, I could read and…
user2052436
  • 4,321
  • 1
  • 25
  • 46
-1
votes
3 answers

counting file characters with fseek

i want to count file chars like this : #include #include int main(){ int d=0; char filename[25]; FILE *file; printf("Enter file name to be read (Text File!) : "); gets(filename); file = fopen(filename,…
shlomi93
  • 1
  • 1
-1
votes
2 answers

C Get a string from a file

I want to get 2 variable strings of fixed length (10chars and 32chars) from a file and save them as variables to pass off later in my program and write them to a new file. I can write the data to a new file from user input but I can't seem to…
jhayton
  • 301
  • 1
  • 10
-1
votes
1 answer

Having problems with fseek() in C

So, I have this function on my program that is supposed to save a "car_str" structure into the desired place on a file specified as a parameter. But when I run it, it keeps overwriting the first slot again and again, as if fseek didn't point to the…
SergiBJ
  • 11
  • 1
-1
votes
1 answer

Method to Batch Update on C Programming

I need to do this Batch Update on a products list. This batch update has to retrieve EVERY product from within the database and get it's "quantity in Order". This "Quantity in Order" then has to be added to the current stock: For e.g: Current in…
DodoSombrero
  • 767
  • 3
  • 15
  • 29
-2
votes
1 answer

when using fread() on a partial line, how do you move to the next line?

Im using fread() and fseek() togather to gather parts of a string. I'm not using fread() on the whole line though. I'd take the whole line but to my knowledge you cannot use fseek() on a character array correct? `int parse(const char *f, const…
1 2 3
27
28