steve005 wrote:
Hi, I am writing a binary file with matlab that consists of a couple
hundred double values and then reading it in with c++. The problem
arises in c++ when I try and read in the files. At a specific point it
stops and wont read any more values. I use this code to open it and
read it:
if( (err = fopen_s( &fp,"C:/simfile1.tmg0" , "rb" )) != 0 );
fread(&coneAngle,sizeof(double),1,fp);
After about twenty simmilar reads it fails, returns an error and quits
reading data. I've
When I change the data it works just fine, I am opening up the file in
binary mode but I think it is hitting an EOF character or something
like that...
I work on a win32 machine, I've compiled it on a mac and it reads all
the data just fine. Is there any way to read the data on a windows
machine and get past this hiccup? I've also tried reading the same
file with ifstream in binary mode with the same results. Any ideas?
Not enough information, but here are a few things to check:
1) How sure are you that a file written "with matlab" is
just a bunch of binary `double' values spliced end-to-end?
1a) How sure are you that the file got from its point of
origin to the system where you're reading it without being
damaged in transit?
2) If you're working in C++, you've asked your question
in the wrong newsgroup: this one's about C.
3) fopen_s() is not part of C. It appears to be some
kind of Microsoft "improvement," but there's no way for us
to be certain of this.
4) If fopen_s() fails (assuming a non-zero value indicates
failure), the code you've posted does not detect it.
5) How do you know that fread() eventually fails? The
code you've posted has no way to tell success from failure.
6) Are you sure the color of your computer's casing is
compatible with the software you're using on it? If you post
a follow-up message, be sure to tell us the color: it's ever
so much more relevant than SHOWING ACTUAL COMPLETE CODE ...
--
Er*********@sun.com