-
My program can't read :(
I am using this code to try to read an entire file into an array
Code:
#include <fstream>
typedef unsigned long int ULI;
.
.
.
ULI M[numElements]; //creates an unsigned long int array, numElements is sufficient to hold the entire file
for(i=0;i<numElements;i++)
{ M[i]=0; }
//open the file
ifstream fin(filename,ios::binary);
//read it into M[]
fin.read((ULI *) &M, flen);
fin.close();
But when I tested it, by printing the contents of M[] to the screen, I just get zeroes for all elements.
What's wrong with the code? It all compiles without any errors. This is in DOS by the way, DJGPP compiler.
-
You need to go through each byte of the file and place that in an element of M. Why are you using unsigned long's?
-
Cos I'm a perverse son of a b****. Well, the algorithm that I'm ripping off uses them. Its part of a file validation signature that I'm building on.
I think the theme of this thread will be engraved on my gravestone when I die. It'll be that long before anyone works out how to do it let alone me!
Ok, ok I give up. How do i read the data into a Char? I'll just have to get it in lumps of four bytes and left shift them into place.
Not very elegant though.