The
fread sounds interesting. I am used to VC++ so some calls here are new to me. First I will show exactly how the lines in the file look like:
Monday,1.1,1.2,1.3,1.4,1.5,1.6,1.7
Tuesday,1.1,1.2,1.3,1.4,1.5,1.6,1.7
Wednesday,1.1,1.2,1.3,1.4,1.5,1.6,1.7
Some questions I wonder:
In the fread(), I understand how fp is pointed to the file that will be red.
mybigbuff, I am not really sure what it stands for but it should be a buffer where data is stored I think ?
The next
1024 should be how many bytes that will be red each time ?
I have put the number of
8 next because I read 8
commadelimited values but I dont know what this number stands for ?
I tried to put the number 1 as in the example in the previous post but the program had an errormessage that said: "Expression: nptr != NULL"
Also I dont know what "rb" stands for in: fopen(fname, "rb"); "r" stands for reading I know.
The second argument should be the mode.
However if I use the code below and read this huge file(130 Mb), the messageBox will show after less than 0.5 sec wich is very fast.
I try to use ofstream OutPut to write some values to a file, but nothing is written.
I wonder if I do this correctly. I find this really interesting as I will read thousands of thousands of these files.
ofstream OutPut;
OutPut.open("C:\\out.txt");
double n1, n2, n3, n4, n5, n6, n7;
const char* fname = "C:\\test130mb.txt";
FILE* fp = fopen(fname, "rb");
char mybigbuff[1024];
while( fread(mybigbuff, 1024, 8, fp) )
{
char* p = strtok(text,",");
p = strtok(NULL, ",");
n1 = atol(p);
p = strtok(NULL, ",");
n2 = atol(p);
p = strtok(NULL, ",");
n3 = atol(p);
p = strtok(NULL, ",");
n4 = atol(p);
p = strtok(NULL, ",");
n5 = atol(p);
p = strtok(NULL, ",");
n6 = atol(p);
p = strtok(NULL, ",");
n7 = atol(p);
OutPut << text << " " << n1 << "\n"; //This does not give any OutPut
}
fclose(fp);
MessageBox::Show("File has Reached End");