If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Strange Problem in File Save

I have faced a strange problem in File Save Routine. I have written a module to save data to binary file . I have designed a structure and put information in that and save it to file . I save multiple such records one after other. I use fwrite , fflush instructions.

The module is working fine. I have saved near about 35 such files. But in one file , the module has saved Blank Records. The file size if perfect but the file is totally blank. It has happened for only one file but need to know the reason.

Re: Strange Problem in File Save

Is it always the same file or does it happen to different files? Have you confirmed that the data you are writing when the file is 'blank' is correct? Have you debugged your code to see what is happening when the file is blank? Are you checking for errors after every api call? If you want further advice and guidance I would suggest that you post a working example that demonstrates the problem.

All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Re: Strange Problem in File Save

Originally Posted by new_2012

I have saved near about 35 such files. But in one file , the module has saved Blank Records. The file size if perfect but the file is totally blank. It has happened for only one file but need to know the reason.

Have you debugged your program? That is the way you find out why a program behaves the way it does.

Also, a program isn't working fine (as you stated) if there is anything wrong with it. Just because it "works" with 35 files, one failure means that you have a bug in your code somewhere and you need to debug it.

Re: Strange Problem in File Save

I'm curious what debugging means to you. If you've been doing it for 10 days and haven't found anything, I doubt you're doing it properly.

What do you expect us to tell you without showing us code. Obviously you're doing something wrong. Use your debugger to verify the buffer you're writing looks correct. Make sure you're checking return values from your I/O functions.

Re: Strange Problem in File Save

Originally Posted by new_2012

I have debugged my code like anything for last 10 days.

You still haven't shown any code. A file being saved as blank should have been debugged within a few minutes, not 10 days. You're simply not debugging correctly, or you're not familiar with how to debug a C++ program.

It is behaving properly and saving data correctly for all other files except that faulty one.

No. The program is not "behaving properly" if one file that you say should be working doesn't work.

When I receive Result Ready flag from interrupt ( Interrupt 11)
I fill up the details (which are ready) and use

fwrite(&resf,sizeof(RES_REC_FLD),1,rf);
fflush(rf);

resf is ResultField (RES_REC_FLD structure) and rf is resultfile.

C++ programming is exact. No amount of describing what you're doing is going to help solve your problem.

You need to show us the actual code. Just because you say you're doing something doesn't mean you're actually doing it or doing it correctly. We need to be convinced that you're doing what you say you're doing, and that is done by showing us the function, or better yet, the entire program that shows you doing these things.

You could be doing something such as overwriting memory, or utilizing variables that aren't initialized, or other C++ issue that affects how the program runs for this particular file. But there is no way any of us will know unless we see the code.

Even I have checked my HDD by scanf for defective sectors.

With a C++ program, you always assume the fault of the program not running correctly is your fault (due to improper coding). You should not initially assume it's a hardware glitch or some other external problem (either hardware or software-related, such as a third-party library).

Then you spend the time to thoroughly debug the program (which I'm not convinced you did), and then give coherent reasons as to why the program behaves the way it does (either it was your code, or a library call was not implemented properly, hardware issue, etc.).

Re: Strange Problem in File Save

My problem is , my code is a big project , so I really don't know how to post the code . but I will try to post the Result file module.
So all the time I posted my Algorithm.

While Debugging ..

I made near about 100 result files , even continuous result file for 8hrs and 16 hrs . I wrote down the key sequences and conditions before each and every file. All the files are fine. Not a single file had any problem.

I kept track that each time the system is getting an interrupt. A counter at input pulse and software counter in the ISR. They matched each other.

I checked for buffer allocation and saved data .. checked syntax again and again .. every thing works fine.

This is c++ but DPMI Based project , I use Borland C++ 4.52 command line compilation and checked all sites and write ups on that.

Pl suggest any other remaining things .. I have read all the posts very sincerely and carefully and I am thinking on them. I say sorry from heart if I have not answered any question.

Re: Strange Problem in File Save

Victor Sir , Only one file in those 35 files is wrong. Even I made more than 100 result files
after that , till date and testing the program again again .. The files are ok. The records are
getting saved properly.

2kaud Sir , I could not debug the program at the time of defective file. This is one and
only one file , which is faulty . The module is working fine after that day and it was working
fine before that day. Every day we run the software , test the components and make result file.
But that day , the system was running fine , the components were tested ok , only result
file was blank.

Paul sir , there is a bug definitely as one file is wrong . so I am worried and working on it
continuously. Why the result fields got corrupted in that file ? and for all records ? ..

Re: Strange Problem in File Save

Originally Posted by new_2012

I made near about 100 result files , even continuous result file for 8hrs and 16 hrs . I wrote down the key sequences and conditions before each and every file. All the files are fine. Not a single file had any problem.

This is not the way to check if the program is sound. A program can run for years without showing any problems, yet can still have a bug hidden away.

You need to duplicate the problem. When the problem is duplicated, you work from that point and see what state the program was in to duplicate the problem and debug using this information.

I kept track that each time the system is getting an interrupt. A counter at input pulse and software counter in the ISR. They matched each other.

First, this technology is over 20 years old, and has been superseded by modern operating systems. You will be hard-pressed to find someone that knows this technology anymore.

But having said that, what you're describing is much more than what you initially started to discuss. You started with an issue with file saving, but if you're doing all of this ISR and interrupt work from MSDOS, don't you think that alone would affect things? From what I remember, doing any file I/O on certain interrupts could even corrupt your hard drive, let alone crash a program.

In other words, if you are going to undertake this project, you better know what you're doing and how to debug it if there are problems. If not, then you should get someone who does, as this is not trivial work.

Re: Strange Problem in File Save

I kept track that each time the system is getting an interrupt. A counter at input pulse and software counter in the ISR. They matched each other.

This is c++ but DPMI Based project , I use Borland C++ 4.52 command line compilation and checked all sites and write ups on that.

Oh crikey! I haven't been involved in this type of work for 25 years - and it was a pain then too!

If I understand what you're saying, when you receive an interrupt 11 (result ready) you then write the file during the interrupt and flush the file to disk. Are you sure that when you receive interrupt 11 it is coming from what you expect and that nothing else in the system is sending interrupt 11? During your processing of interrupt 11 can other interrupts occur or have you disabled interrupts during the write routine? Is this a system that has been working and has developed this behaviour since you're changed it - or is this a new system that you're written from scratch?

All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Re: Strange Problem in File Save

paul sir , I have no escape and will have to use the DPMI mode.
But I will keep all your instructions in mind and will try a lot again. I am trying to duplicate the problem but not successful. but will try more.

2kaud sir ... what a correct algorithm . Only the thing is that I dont write data to file in ISR. I fill necessary information in ResultField and raise a flag in ISR. Then in normal prog main loop actually fwrite and fflush work. These instructions are time consuming and may lead to hang up. Another point is that , we have a 10ms interrupt running all the time in the system and taking care of different episodes. I will try to disable and enable that at File Write. but this seems to be a problem. As I am receiving data continuously and processing that in 10ms (which takes 1us. Data rate is 6000 samples/second). but I will definitely try this.

I really thank all of you for your valuable support.
This site is helpful to me write from c++ to CSharp.

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.