Reputation: 1
I am using quadmath library for quad-precision. Can I use fwrite function to write to binary file?
struct rec
{
__float128 mydata;
}
struct rec my_record;
mydata=1.41421356237309504880q;
fwrite(&my_record, sizeof(struct rec), 1, myfile);
Upvotes: -1
Views: 147
Reputation: 225344
You should have no problem writing to a file. As long as you read it back in the same way (i.e. with fread
) and the file isn't copied between machines you should be fine.
You also don't need to encapsulate the value in a struct to do this:
__float128 mydata;
int rval;
mydata=1.41421356237309504880q;
rval = fwrite(&mydata, sizeof(mydata), 1, myfile);
if (rval < 1) {
perror("failed to write record");
}
...
rval = fread(&mydata, sizeof(mydata), 1, myfile);
if (rval < 1) {
perror("failed to read record");
}
Upvotes: 0