ftell is a standard C library function which returns the current offset in a file or stream in relation to the first byte.
Questions tagged [ftell]
70 questions
0
votes
0 answers
(Windows) Using ftello() returns incorrect file size for "some" binary files
I use fseeko to move the file pointer to the file end first, then use ftello to get the binary file size. I refer to this page Do not use fseek... and follow exactly the same code in "Compliant Solution (POSIX ftello())" section.
My problem is this…

ctheadn8954
- 129
- 1
- 8
0
votes
1 answer
_popen(dir, rt) fseek(dir, and ftell() returns 0
In this code, the ftell(dir) returns 0. But when I read with fread_s(), all the intended text is appearing. Any idea why ftell() returns 0 in this situation ?
FILE* dir = _popen("dir", "rt");
if (dir == NULL) {
send(socket, "0", 10, 0);
…

HellDryx
- 5
- 1
0
votes
1 answer
Displaying portion of text from text file in C
I have a text file and I wanted to extract only a specific part of it at a particular time.For that ,I used ftell() while writing to note the start and end positions and then use fseek() to jump to that particular location.
int main()
{
…

SARTHAK MEHRA
- 3
- 7
0
votes
2 answers
Does fscanf move the file pointer backwards?
These are the contents of my file, 'unsorted.txt' :
3 robert justin trump
This is my code:
#include
int main(void) {
FILE *f = fopen("unsorted.txt", "r");
char n;
printf("%d\n", ftell(f));
fscanf(f, "%s", &n);
int l…

Novice
- 73
- 5
0
votes
0 answers
Weird behavior of ftell and fseek reading a txt file
I'm trying to read a txt file containing a "picture" (a matrix of chars) and ftell and fseek seem to be working in a different way than what i was taught in class and on the web.
Here is the code:
fp = fopen(filename,…

Lior Yang Eliav
- 25
- 4
0
votes
1 answer
fseek() and ftell() fail in a loop
I need to loop trough a directory, data and read each file, that meets certain conditions, in a string and do something with it. For some reason it fails after the fseek call (the output is only the name of the first file in the directory).
Any idea…

Petr Kroupa
- 53
- 3
- 8
0
votes
4 answers
Displaying size of a file [C]
I'm making a simple sockets program to send a text file or a picture file over to another socket connected to a port. However, I want to also send the size of the file over to the client socket so that it knows how many bytes to receive.
I also want…

Jack S
- 43
- 2
0
votes
1 answer
LibXML2 + pull parser (stax) : stream position (ftell) of the event ?
I'd like to create an index and later, access some specific parts of a huge xml file, so I need to get the offset ( ftell ... ) for some 'startElement' Events.
Using the pull parser (stax) interface of libxml2 (…

Pierre
- 34,472
- 31
- 113
- 192
0
votes
0 answers
fseek, ftell resulting in segmentation fault
I am trying to seek till the end of a file using fseek, seeking in steps of 2560 * 5 bytes at a time. No idea why I am getting a segmentation fault
I am running this code on TDA2x board. Is here a problem in the particular environment which I am…

Sushant
- 151
- 1
- 7
0
votes
2 answers
fseek() sets the pointer to wrong position
I have a .dat file with the following structure:
Object name | Area | Length |Form Factor
I am trying the find which object has the minimum area. I read the whole file and keep track of the object with the minimum area, and its position with…

massakrienen
- 266
- 2
- 3
- 14
0
votes
3 answers
Reading from a file and setting an offset?
I am new to C, and I am trying to build a C program that scans through a file until EOF, picks out lines that contain a certain keyword and then sets an offset after the last line was searched. When the scan is executed again, it scans the file,…

roxycandigit
- 1
- 1
- 2
0
votes
3 answers
a+ and a mode with fopen()
According to the manual, if you select a/a+ mode in the fopen() function, the file pointer will be placed at the end.
But why do I get 0 using the ftell() and the feof() still returns false? If the file pointer is at the…

ray
- 29
- 1
- 2
0
votes
0 answers
ftell/fgetpos cannot get correct position when handling UTF-8 text file
Test Under VStudio 2012 + Win7
The UTF-8 text file contains merely 5 bytes:
31 0a 32 0a 0a
in text mode it will be shown like:
1
2
The source is also straightforward:
FILE *fp;
TCHAR buf[100] ={0};
TCHAR *line;
LONG pos;
_tfopen_s(&fp,…

tiancheng
- 21
- 3
0
votes
3 answers
malloc() not allocating enough space
Hello here is my problem
FILE *sourcefile;
if ((sourcefile = fopen(argv[1],"r")) == NULL) //Opens File
{
printf("Error: Could not open %s\n",argv[1]);
return 0;
}
fseek(sourcefile, 0 , SEEK_END); // Sets file pointer at the end of the…

apboutos
- 109
- 2
- 16
0
votes
2 answers
finding reoccuring string in I/O stream -C?
I'm quite new to C. I'm trying to write a code that finds a string in a I/O stream, and I don't understand what I'm doing wrong. I know the error is probably in the large while loop (in the code below).
I want the function to return the location in…

jilin
- 3
- 1