On this page
ftell
Prev: fseek | Up: stdio.h | Next: fflush
Rel: stdio.h, stdio.h & File I/O Guide
Ref: cppreference — ftell
Tags: #public #prog #c #stdlib #stdio #tier/standard
Include
#include <stdio.h>
Signature & Overview
long ftell(FILE *stream);
Returns the current byte offset in stream (or -1L on error).
Notes & Pitfalls
- Returns
-1Lon error (e.g., non-seekable pipes/stdin) and returnslong(limited to 2 GiB on 32-bitlongplatforms).
Example
#include <assert.h>
#include <stdio.h>
int main(void) {
FILE *f = tmpfile();
fputs("1234", f);
assert(ftell(f) == 4);
fclose(f);
}
Linked from
Related notes
- tuts/c/stdlib/stdio/fflush Linked here; links to this page; shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fseek Linked here; links to this page; shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio Linked here; links to this page; shared tags: #c, #prog, #stdio, #stdlib
- tuts/c/stdlib/stdio_and_file_io Linked here; shared tags: #c, #prog, #stdlib
- tuts/c/stdlib/stdio/fclose shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/feof shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/ferror shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fgets shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fopen shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fprintf shared tags: #c, #prog, #stdio, #stdlib, #tier