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
- Getting infinite loop after entering 2 objects to…
- no match for ‘operator
- Is it possible to apply CSS to half of a character?
- How to get the real and total length of char * (char array)?
- Fastest way to iterate over all the chars in a String
- How to get vaadin-grid to fill the page
- Can't find why this datetime test fails, in F#
- How to allocate aligned memory only using the…
- SQL Server: Query fast, but slow from procedure
- error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or…
- Do I cast the result of malloc?
- Is there any possible way to loop strcmp function in…
- How to read the content of a file to a string in C?
- Undefined reference to 'vtable for xxx'
- How to get the length of an array in C? Is "sizeof"…
- Using malloc for allocation of multi-dimensional…
- Simple C example of doing an HTTP POST and consuming…
- Why use double indirection? or Why use pointers to pointers?
- How is malloc() implemented internally?
- GLYPHICONS - bootstrap icon font hex value
- Implementation of user defined array on stack and/or…
- Same program is 10 times slower on windows
- Split string in C every white space
- Efficient Algorithm for Bit Reversal (from…
- C Programming: How to read the whole file contents…
- load list from file in c
- How to multiply values using SQL
- Allocating an array of strings when needed in C
- Why are elementwise additions much faster in…
- Reading a file character by character in C
- Replacing a 32-bit loop counter with 64-bit…
- Size of character ('a') in C/C++
- How do malloc() and free() work?
- How to use html template with vue.js
- Error Message : Cannot find or open the PDB file
- Length of array in function argument
- python 3.2 UnicodeEncodeError: 'charmap' codec can't…
- malloc for struct and pointer in C
- When to use malloc for char pointers
- Returning a C string from a function
- How can I create an executable to run a kernel in a…
- error: strcpy was not declared in this scope
- Draw multiple lines using OpenGL 3.0+ in C
- select unique rows based on single distinct column
- Append to the end of a file in C
- How do I determine the size of my array in C?
- How to filter a RecyclerView with a SearchView
- Reading and writing to serial port in C on Linux
- What is the difference between new/delete and malloc/free?
- Difference between malloc and calloc?
- What does "dereferencing" a pointer mean?
- Copy a file in a sane, safe and efficient way
- Recovering structs sent over a network
- C free(): invalid pointer
- ember: understand errors
- Ukkonen's suffix tree algorithm in plain English
- What does void* mean and how to use it?
- what is the size of an enum type data in C++?
- mmap memory backed by other memory?
- Best way to check for "empty or null value"
- Win32 - Button images appear in wrong order in toolbar
- Clarifying with references if malloc() allocates or…
- How to pass 2D array (matrix) in a function in C?
- Grouped bar plot in ggplot
- Can any one please help me what wrong with this code?
- How do I work with dynamic multi-dimensional arrays in C?
- How to write an application to control a driver…
- Returning an array using C
- Guzzlehttp - How get the body of a response from Guzzle 6?
- Element count of an array in C++
- Improve INSERT-per-second performance of SQLite
- Dynamically create an array of strings with malloc
- How to convert string to char array in C++?
- What's wrong with 'template int compare(char p1 [N],…
- Start redis-server with config file
- How to find memory leak in a C++ code/project?
- Generate SQL Create Scripts for existing tables with Query
- How to create a fix size list in python?
- #define macro for debug printing in C?
- Difference between modes a, a+, w, w+, and r+ in…
- Return char/string from a function
- Reversing a string in C
- Casting a void pointer (that is part of a struct)…
- Why do I get a C malloc assertion failure?
- Allocate small struct to 32 bit aligned in 64 bit system
- Why heap allocation uses a lot of memory than stack…
- Why does C++ code for testing the Collatz conjecture…
- Trying to pass an array with variable size and it's…
- How do I print out the contents of a vector?
- Quick Way to Implement Dictionary in C
- How to remove white space characters from a string…
- Error: invalid operands of types ‘const char ’…
- Update backbone model on change of global variable?
- TypeError: expected a character buffer object -…
- How, in general, does Node.js handle 10,000…
- How to compile C++ under Ubuntu Linux?
- Returning full array C++?
- Best practice multi language website
- Convert pem key to ssh-rsa format