LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

fatal run-time error

Hello,
 
I´ve a very big problem.
My application get a fatal run-time error when I want to work with an open file, but only in debug-mode.

 

p_to_file = fopen (file, "ab");                                                                       

if(p_to_file != 0)                                                                                                                   

{

state = fseek (p_to_file, pos, SEEK_SET);  //Here it says that the Argument must be an open stream

fwrite (&value, sizeof(double), 1, p_to_file);                                       

            fclose (p_to_file);                                                                                                       

}

 
I don´t understand it!
When I run the .exe of my application there is no error and the var state is zero.
 
I tried to disable the message (SetBreakOnLibraryErrors(false)), but the error comes again.
 
Thanks
Andrea
0 Kudos
Message 1 of 5
(3,444 Views)
I tried some tests with your code in Interactive execution window and although I got no error I noticed one detail that maybe can help you in your application. You may be getting a conflict between opening the file in append mode and setting the position after end-of-file indicator: in my test I was not able to set a position after end of file, even if I never had an error. Can you try opening the file in "rb+" mode and see if you get the same error? This file mode permits you to write even after end of file (file content between previous end-of-file and the new elements written remains undefined).
 


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 5
(3,433 Views)

I tried it, but the error stays.

I don´t understand, why the exe runs.

Only when I debug my app. , I get the error.

Could it be, that my program is too large? I´ve over 7000 lines of code!

0 Kudos
Message 3 of 5
(3,430 Views)

Do you have write permission on the file? Is it open for access by another program at the same time?

JR

0 Kudos
Message 4 of 5
(3,427 Views)

I have write permission. No other program can open the file, when it´s already open.

I think it runs now. I renamed the file-pointer and now it works. But I don´t understand why!!!

0 Kudos
Message 5 of 5
(3,423 Views)