Strange Problem in File Save
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: Strange Problem in File Save

  1. #1
    Join Date
    Jan 2012
    Location
    India
    Posts
    138

    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.

    Pl help .. thank u.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,392

    Re: Strange Problem in File Save

    it sounds like you saved wrong ("Blank") data in this file.
    Since you didn't show your code it is not possible to say more...

    BTW, how often did it happen? Only once (one file from 35 had saved wrong) or it happens regulary?
    Victor Nijegorodov

  3. #3
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,389

    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.

  4. #4
    Join Date
    Apr 1999
    Posts
    27,427

    Re: Strange Problem in File Save

    Quote Originally Posted by new_2012 View Post
    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.

    Regards,

    Paul McKenzie

  5. #5
    Join Date
    Jan 2012
    Location
    India
    Posts
    138

    Re: Strange Problem in File Save

    Many thanks for all of you.

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

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

    I save data to different files.

    I have checks on whether records are getting saved or not.

    The records in other files are ok but defective file has blank records. Even length of record , no. of records and file length are matching. Only the data is blank.

    But this is serious if my customer looses his testing data.

    The code is simple ..

    ResultField is a structure , that contain Serial No. , Status ,
    Coordinates , length information , frequency of testing , gain at
    the test.

    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.


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

    pl pl guide.

  6. #6
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,389

    Re: Strange Problem in File Save

    It is behaving properly and saving data correctly for all other files except that faulty one.
    As I asked previously, is it always the same faulty one?
    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.

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,392

    Re: Strange Problem in File Save

    Quote Originally Posted by new_2012 View Post
    The code is simple ..

    ResultField is a structure , that contain Serial No. , Status ,
    Coordinates , length information , frequency of testing , gain at
    the test.

    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.


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

    pl pl guide.
    I do NOT see any code in this post!
    Note that posting pseudo-code causes us to post you pseudo-answers!
    Victor Nijegorodov

  8. #8
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,098

    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.

  9. #9
    Join Date
    Apr 1999
    Posts
    27,427

    Re: Strange Problem in File Save

    Quote Originally Posted by new_2012 View Post
    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.
    The code is simple ..

    ResultField is a structure , that contain Serial No. , Status ,
    Coordinates , length information , frequency of testing , gain at
    the test.

    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.).

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; July 10th, 2013 at 10:39 AM.

  10. #10
    Join Date
    Jan 2012
    Location
    India
    Posts
    138

    Unhappy Re: Strange Problem in File Save

    Very very thanks for all of you , you have always helped me a lot.

    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.

    Pl pl guide.

  11. #11
    Join Date
    Jan 2012
    Location
    India
    Posts
    138

    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 ? ..


    Pl pl give me any clues if possible ..

  12. #12
    Join Date
    Apr 1999
    Posts
    27,427

    Re: Strange Problem in File Save

    Quote Originally Posted by new_2012 View Post
    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.

    Regards,

    Paul McKenzie

  13. #13
    Join Date
    Apr 1999
    Posts
    27,427

    Re: Strange Problem in File Save

    Quote Originally Posted by new_2012 View Post
    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 ? ..
    You keep asking "why", but no one knows without being your partner in debugging the code (and also have knowledge of interrupts and MSDOS).

    Regards,

    Paul McKenzie

  14. #14
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,389

    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.

  15. #15
    Join Date
    Jan 2012
    Location
    India
    Posts
    138

    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.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center