Posted By: Nino
How can I find out the size of a file I opened with an application written in C ?
I would like to know the size, because I want to put the content of the loaded file into a string, which I allocate using
malloc(). Just writing
malloc(10000*sizeof(char)); is IMHO a bad idea.
You need to seek to the end of the file and then ask for the position:
fseek(fp, 0L, SEEK_END); sz = ftell(fp);
You can then seek back, e.g.:
fseek(fp, 0L, SEEK_SET);
or (if seeking to go to the beginning)
Answered By: Rob Walker
- problem with client server unix domain stream…
- C threads corrupting each other
- no match for ‘operator
- Getting infinite loop after entering 2 objects to…
- update file based on a key in C
- Is it possible to apply CSS to half of a character?
- Creating an dynamic array, but getting segmentation…
- Fastest way to iterate over all the chars in a String
- How to get the real and total length of char * (char array)?
- Getting weird compilation error in defining a…
- Can't find why this datetime test fails, in F#
- GLYPHICONS - bootstrap icon font hex value
- How to get vaadin-grid to fill the page
- How to allocate aligned memory only using the…
- OpenCL - Approximation of Pi via Monte Carlo…
- SQL Server: Query fast, but slow from procedure
- Unexpected behaviour of lseek
- Is there any possible way to loop strcmp function in…
- error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or…
- Undefined reference to 'vtable for ✘✘✘'
- LNK2019 sÃmbolo externo public: bool __thiscall â€¦…
- Do I cast the result of malloc?
- Simple C example of doing an HTTP POST and consuming…
- Re-arrange position in a table maitaining order
- How to get the length of an array in C? Is "sizeof"…
- How to read the content of a file to a string in C?
- Segmentation fault when decrypting with openssl in C
- Using malloc for allocation of multi-dimensional…
- Matrix not received properly with MPI_Send and MPI_Recv
- Why use double indirection? or Why use pointers to pointers?
- How do I include certain conditions in SQL Count
- Octave using 'for' statement to show two animations…
- How is malloc() implemented internally?
- Implementation of user defined array on stack and/or…
- Appending data to json file in C: append stops after…
- Split string in C every white space
- Efficient Algorithm for Bit Reversal (from…
- Same program is 10 times slower on windows
- Error Message : Cannot find or open the PDB file
- How to show title in hover - css / jquery
- How to multiply values using SQL
- How to initalize a array of string from a file data
- load list from file in c
- C program that replace word in sentence to another word
- C Programming: How to read the whole file contents…
- ember: understand errors
- Inputing and reading realy long numbers over 200…
- How to use html template with vue.js
- Allocating an array of strings when needed in C
- Why are elementwise additions much faster in…
- Reading a file character by character in C
- Size of character ('a') in C/C++
- Replacing a 32-bit loop counter with 64-bit…
- CUDA: Pass device function as an argument to global function
- Returning a C string from a function
- How do malloc() and free() work?
- error: strcpy was not declared in this scope
- Length of array in function argument
- python 3.2 UnicodeEncodeError: 'charmap' codec can't…
- How can I create an executable to run a kernel in a…
- When to use malloc for char pointers
- Meaning of sizeof(char) *100
- How to filter a RecyclerView with a SearchView
- malloc for struct and pointer in C
- Incomplete pointer array to struct. Stack smashing detected
- select unique rows based on single distinct column
- Having trouble with my nav bar/header, It used to…
- Copy a file in a sane, safe and efficient way
- Getting "Abort trap 6" using memset()
- store struct of info in single linked list
- Can't understand the difference between declaring a…
- Ukkonen's suffix tree algorithm in plain English
- Draw multiple lines using OpenGL 3.0+ in C
- Segmentation Core Dump Problem in Dijkstra Algorithm
- Reading input input into a char pointer with scanf
- C++ OpenGL stb_image.h errors
- Adobe XD to responsive html
- Reading and writing to serial port in C on Linux
- Why my "title" bloc doesn't go to bottom?
- C++ Custom Exception classes
- Append to the end of a file in C
- What does "dereferencing" a pointer mean?
- How do I determine the size of my array in C?
- Read lines with spaces in a txt file
- Grouped bar plot in ggplot
- Recovering structs sent over a network
- Iterate and sum values based on a condition in pandas
- InfluxDB - ERR_EMPTY_RESPONSE - Used to come up in…
- Best way to check for "empty or null value"
- Binance WebSocket Order Book - depths change every time
- Difference between malloc and calloc?
- C free(): invalid pointer
- Improve INSERT-per-second performance of SQLite
- What is the difference between new/delete and malloc/free?
- Guzzlehttp - How get the body of a response from Guzzle 6?
- How to write an application to control a driver…
- A function in C that adds a node at the end of a…
- Returning an array using C