R
ryanselk
Hey all, I have a c function im putting into c++ (dont ask why, tell
you the truth, I really dont know!). I am having a bit of problem
deciding on how to use a new method of fread.
Here is the (working) C code:
float read_p(FILE *file, int datatype)
{
float res;
unsigned char u, b1, b2;
switch(datatype)
{
case 1:
fread(&u, sizeof(unsigned char), 1, file);
res = u;
break;
case 4:
fread(&res, sizeof(float), 1, file);
break;
default:
printf ("\n Error \n\n");
res = 0.0;
exit(1);
}
return res;
}
Here is what I have so far.. (I had to re-do some of the file IO).
float read_p(ifstream &file1, int datatype)
{
float res;
unsigned char u, b1, b2;
switch(datatype)
{
case 1:
fread(&u, sizeof(unsigned char), 1, &file1);
res = u;
break;
case 4:
fread(&res, sizeof(float), 1, &file1);
break;
default:
cout<<"Error"<<endl;
res = 0.0;
exit(1);
}
return res;
}
Anyone have a comment on how I could use something like fread? Sorry I
am not very good at c++! Havnt used it in years.
you the truth, I really dont know!). I am having a bit of problem
deciding on how to use a new method of fread.
Here is the (working) C code:
float read_p(FILE *file, int datatype)
{
float res;
unsigned char u, b1, b2;
switch(datatype)
{
case 1:
fread(&u, sizeof(unsigned char), 1, file);
res = u;
break;
case 4:
fread(&res, sizeof(float), 1, file);
break;
default:
printf ("\n Error \n\n");
res = 0.0;
exit(1);
}
return res;
}
Here is what I have so far.. (I had to re-do some of the file IO).
float read_p(ifstream &file1, int datatype)
{
float res;
unsigned char u, b1, b2;
switch(datatype)
{
case 1:
fread(&u, sizeof(unsigned char), 1, &file1);
res = u;
break;
case 4:
fread(&res, sizeof(float), 1, &file1);
break;
default:
cout<<"Error"<<endl;
res = 0.0;
exit(1);
}
return res;
}
Anyone have a comment on how I could use something like fread? Sorry I
am not very good at c++! Havnt used it in years.