Skip to main content

Questions tagged [ftell]

ftell is a standard C library function which returns the current offset in a file or stream in relation to the first byte.

1 vote
2 answers
89 views

Should I prefer using basic_istream::tellg() or filesystem::file_size()?

Suppose I have a std::filesystem::path, which I then open as an std::ifstream, and suppose that I want to determine its size (e.g. maybe I want to read the whole file). Should I prefer calling auto ...
einpoklum's user avatar
  • 127k
1 vote
0 answers
51 views

Error writes wrong buffer to file using ftell and fseek (C)

I wrote a code that reading line by line from a text file and store the value in a variable called buffer using fgets, after reading each line I am sending the buffer to a function that suppose to ...
roee's user avatar
  • 105
-1 votes
1 answer
89 views

fscanf changing file position to a negative value

I have code for processing a file having numbers at the beginning, which I have to read, and then letters. I need to print letters with index corresponding to the numbers at the beginning of the file, ...
Bartek Olczak's user avatar
2 votes
0 answers
298 views

seek() and tell() in text mode, file handling python

I learnt that f.tell() returns an integer giving the file object’s current position in the file represented as number of bytes from the beginning of the file when in binary mode and an opaque number ...
harshit's user avatar
  • 75
0 votes
1 answer
693 views

ftell returning inaccurate value

So, I have this piece of code in c that is supposed to read from an ascii file and then return a string that is parsed and compiled into bytecode. When I try to get the size of a file using ftell, it ...
Boy boy's user avatar
  • 63
0 votes
0 answers
29 views

Using file functions to reverse the characters in the file [duplicate]

So, using fseek and ftell function I am trying to print the characters one at a time by first pointing to the end of the file using fseek and then decrementing the value of ftell to print the last ...
dv24680's user avatar
  • 63
0 votes
0 answers
325 views

while writing data in .dat file with the help of fwrite() function using in loop, why at random positions the null blocks are created in memory?

Code of 121_5.c ( 121_5.c is a program name) #include<stdio.h> typedef struct student { char name[40]; int age; }STUDENT; // size is 44 bytes int main() { int i; char ch; ...
Abhishek Mane's user avatar
2 votes
2 answers
529 views

Reverse printing from txt file using recursion in C

I need to write out .txt file backwards in terminal using recursion, but it seems I'm stuck. This is my code so far, but it creates an infinite loop. Also, the procedure write() should have only 1 ...
Cassie's user avatar
  • 43
0 votes
1 answer
143 views

Cannot assign the return value of ftell function to a char array size

I am trying to print some values from a file with minimum allocated memory. I have used ftell() to find out the file, thus, to minimize used memory. I did 3 approaches and one of them was successful. ...
max's user avatar
  • 185
3 votes
2 answers
398 views

ftell/fseek fail when near end of file

Reading a text file (which happens to be a PDS Member FB 80) hFile = fopen(filename,"r"); and have reached up to the point in the file where there is only an empty line left. FilePos = ...
Morag Hughson's user avatar
1 vote
2 answers
1k views

How the ftell() function works?

I have this code and I don't understand how it works: void print(char * fileName) { FILE * fp; int ch; fp = fopen(fileName, "r"); while (ftell(fp) < 20) { ch = ...
learnCforme's user avatar
1 vote
1 answer
757 views

CStdioFile cannot work with files larger than 2GB?

I am using Visual C++ 2008. In VC++ 2008, CFile supports 2^64 huge files. So I think CStdioFile should also support. However, when using CStdioFile::GetLength() on a file larger than 2GB, I get a ...
alancc's user avatar
  • 571
1 vote
2 answers
524 views

Ftell for text files

I use this little program to understand how ftell works. I created a txt file and i typed in "15" and below that, in a second line, "no". So what I expected was it to print 0, then after it reads 15, ...
Johnny's user avatar
  • 25
2 votes
4 answers
2k views

Should I check the return value of fseek() when calculating the length of a file?

I have this idiomatic snippet for getting the length of a binary file: fseek(my_file, 0, SEEK_END); const size_t file_size = ftell(my_file); …I know, to be pedantic fseek(file, 0, SEEK_END)...
madmurphy's user avatar
  • 1,691
0 votes
1 answer
330 views

wrong size of IJVM chunk file in c question

I am trying to implement an IJVM an read a binary file. I understand that an .ijvm file contains a 32-bit magic number and any number of data blocks and that a data block has three parts. My ...
sir Hoyle's user avatar

15 30 50 per page
1
2 3 4 5