Is the following the correct way to get the number of bytes in a file? Are there more straightforward ways, perhaps directly from the FILE* object? size_t num_bytes(FILE *fp) {     fseek(fp, 0, SEEK_END);     return (size_t) ftell(fp); }  Additionally, why does ftell return a long int and not a size_t object? I find it a bit difficult to figure out which &quot;size-ish&quot; functions return size_t and which don't. Is there a good way to remember that? Or is the reason that ftell isn't size_t because it uses -1L as the &quot;fail value&quot; ?
11872
How can I figure out the size of a file, in bytes?  #include &lt;stdio.h&gt;  unsigned int fsize(char* file){   //what goes here? }
70083
I'm trying to find out how much memory my objects take to see how many of them are ending up on the  (which is anything over 85,000 bytes). Is it as simple as adding 4 for an int, 8 for a long, 4 (or 8 if you're on 64 bit) for any reference types etc for each object, or are there overheads for methods, properties, etc.?
38175
For example: sizeof(char*) returns 4.  As does int*, long long*, everything that I've tried.  Are there any exceptions to this?
96433
I need to find a file in my current directory whose size should be less than or equal to 10 MB.  ls -lh gives me the file size of each file but not sure how to find the files whose size are less than or equal to 10 MB.  host@407d:t1_snapshot$ ls -lth   Is there any way I can do that?
114370
This is about files straight from the compiler, say g++, and the -o (outfile) flag.  If they are binary, shouldn't they just be a bunch of 0's and 1's?  When you cat them, you get unintelligible output but also intact words.  If you file them, you get the answer immediately - there seem to be no computation. Do the binary files in fact have headers with this kind of information?  I thought a binary executable was just the program just compiled, only in the form of machine instructions that your CPU can instantly and unambiguously understand. If so, isn't that instruction set just bit patterns? But then, what's all the other stuff in the binaries? How do you display the bits?  Also, if you somehow get hold of the manual of your processor, could you write a binary manually, one machine instruction at a time? That would be terribly ineffective, but very fascinating if you got it to work even for a "Hello World!" demo.
222
In several C++ examples I see a use of the type size_t where I would have used a simple int. What's the difference, and why size_t should be better?
62020
I'm trying to approximate the computer's write speed using dd:  dd if=/dev/urandom of=/dev/null bs=1K count=10000   which gives the following output  10000+0 records in 10000+0 records out 10240000 bytes (10 MB) copied, 0.746313 s, 13.7 MB/s   How can I get the '13.7 MB/s' into a bash variable? I've tried piping the output from dd to progs like awk, sed and grep to no avail.  Ultimately, I'm calling this via os.system(...) from within a python script. If anyone knows of a more direct way to get a similar result inside python I'd be interested in that also. I'm trying to predict how long a file copy will take, based on the file size.  Any help would be greatly appreciated.
75269
As per c99 standard, size of long long should be minimum 64 bits. How is this implemented in a 32 bit machine (eg. addition or multiplication of 2 long longs). Also, What is the equivalent of long long in C++.
52835
fopen is failing when I try to read in a very moderately sized file in PHP.  A 6 meg file makes it choke, though smaller files around 100k are just fine.  i've read that it is sometimes necessary to recompile PHP with the -D_FILE_OFFSET_BITS=64 flag in order to read files over 20 gigs or something ridiculous, but shouldn't I have no problems with a 6 meg file?  Eventually we'll want to read in files that are around 100 megs, and it would be nice be able to open them and then read through them line by line with fgets as I'm able to do with smaller files.  What are your tricks/solutions for reading and doing operations on very large files in PHP?  Update:  Here's an example of a simple codeblock that fails on my 6 meg file - PHP doesn't seem to throw an error, it just returns false.  Maybe I'm doing something extremely dumb?  $rawfile = "mediumfile.csv";  if($file = fopen($rawfile, "r")){     fclose($file); } else {   echo "fail!"; }   Another update:  Thanks all for your help, it did turn out to be something incredibly dumb - a permissions issue.  My small file inexplicably had read permissions when the larger file didn't.  Doh!
26276
A few weeks back I was using std::ifstream to read in some files and it was failing immediately on open because the file was larger than 4GB. At the time I couldnt find a decent answer as to why it was limited to 32 bit files sizes, so I wrote my own using native OS API.  So, my question then: Is there a way to handle files greater than 4GB in size using std::ifstream/std::ostream (IE: standard c++)  EDIT: Using the STL implementation from the VC 9 compiler (Visual Studio 2008).  EDIT2: Surely there has to be standard way to support file sizes larger than 4GB.
981
How do I determine the size of my array in C?   That is, the number of elements the array can hold?
50721
Is there a TeX command that returns the width of a given text as length value, so that I can use the result directly as a length argument of another command?  I mean, I would like to have a command \getWidth{my text} and want to use the result directly as the first argument of \parbox:  \parbox{\getWidth{my text}}{my foo\\bar text}
15305
Example: I have the file "mybinaryfile", and the contents in hex are:  A0 01 00 FF 77 01 77 01 A0   I need to know how many A0 bytes there are in this file, how many 01, and so on. The result could be:  A0: 2 01: 3 00: 1 FF: 1 77: 2   Is there some way to make this count directly in shell or do I need to write a program in whatever language to do this specific task?
39976
Is there a better way than simply trying to open the file?  int exists(const char *fname) {     FILE *file;     if ((file = fopen(fname, "r")))     {         fclose(file);         return 1;     }     return 0; }
2266
In follow up to , it appears that some numbers cannot be represented by floating point at all, and instead are approximated.  How are floating point numbers stored?  Is there a common standard for the different sizes?  What kind of gotchas do I need to watch out for if I use floating point?  Are they cross-language compatible (ie, what conversions do I need to deal with to send a floating point number from a python program to a C program over TCP/IP)?
20515
This question was inspired by a similar question:   My question is a little different:  Is there any way to determine the size of a C++ array programmatically?  And if not, why?  Every function I've seen that takes an array also requires an integer parameter to give it the size.  But as the linked question pointed out, delete[] must know the size of the memory to be deallocated.  Consider this C++ code:  int* arr = new int[256]; printf("Size of arr: %d\n", sizeof(arr));   This prints "Size of arr: 4", which is just the size of the pointer.  It would be nice to have some function which prints 256, but I don't think one exists in C++.  (Again, part of the question is why it doesn't exist.)  Clarification: I know that if I declared the array on the stack instead of the heap (i.e. "int arr[256];") that the sizeof operator would return 1024 (array length * sizeof(int)).
111191
I'm trying to find all duplicate files (based on MD5 hash) and ordered by file size. So far I have this:  find . -type f -print0 | xargs -0 -I "{}" sh -c 'md5sum "{}" |  cut -f1 -d " " | tr "\n" " "; du -h "{}"' | sort -h -k2 -r | uniq -w32 --all-repeated=separate   The output of this is:  1832348bb0c3b0b8a637a3eaf13d9f22 4.0K   ./picture.sh 1832348bb0c3b0b8a637a3eaf13d9f22 4.0K   ./picture2.sh 1832348bb0c3b0b8a637a3eaf13d9f22 4.0K   ./picture2.s  d41d8cd98f00b204e9800998ecf8427e 0      ./test(1).log   Is this the most efficient way?