CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 3 of 3 FirstFirst 123
Results 31 to 42 of 42
  1. #31
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    here is your problem, fix the logic.
    your opening two handles.
    Code:
    if ((file = fopen((char*)filename,"r")) == NULL)
    	{
    //	    AfxMessageBox("Can not open the file: " + filename);  
    		bprocessingError=true; // Can not read the file
    	}
    
       else if ((file = fopen( (char *)filename,"r")) != NULL)

  2. #32
    Join Date
    Dec 2003
    Posts
    220
    Originally posted by Mick
    here is your problem, fix the logic.
    your opening two handles.
    Code:
    if ((file = fopen((char*)filename,"r")) == NULL)
    	{
    //	    AfxMessageBox("Can not open the file: " + filename);  
    		bprocessingError=true; // Can not read the file
    	}
    
       else if ((file = fopen( (char *)filename,"r")) != NULL)
    Mick, I think the zip file and what you posted is the same, I checked it out already...

  3. #33
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    Originally posted by Homestead
    Mick, I think the zip file and what you posted is the same, I checked it out already...
    What do you mean? The zip file and the logic in the parse function is what I commented on. That is where the error lies.

  4. #34
    Join Date
    Dec 2003
    Posts
    220
    Originally posted by Mick
    What do you mean? The zip file and the logic in the parse function is what I commented on. That is where the error lies.
    I didnt see the logic error you were talking about, I just think the error lies in
    PHP Code:
       FILE   *file NULL;                // Handle to the file 
    and
    PHP Code:
       bprocessingError true;//ERROR I think because this will be always true then
       
    if ((file fopen((char*)filename,"r")) == NULL)
        {
    //        AfxMessageBox("Can not open the file: " + filename);  
            
    bprocessingError=true// Can not read the file
        

    and here
    PHP Code:
      if ( bprocessingError )
       {
          goto exit;
       } 
    Mick, I received from you competitive nature...
    Last edited by Homestead; January 20th, 2004 at 04:18 AM.

  5. #35
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    would you like me to explain?

    first off what he posted as code snippets, and what he posted as the .zip are two different things, we could have been here all day, had the .zip not been posted.

    Lets take a look at what happens in the if clause.

    because of precedence the function fopen in the if clause gets executed first, it returns a valid handle and places it in file. It then test to see if file is null, this is false, it is valid, it will then JNE (jump if not equal) to the next clause the else if.

    It will again, execute the fopen, and push a NEW file handle into file, we now have two file handles open to the same file, one of which is 'dangling' it then tests if the file handle is not null, it isn't so we drop into the block and execute the stat etc.

    the remove(...) will fail as there is still an open file handle.

    though I normally don't make these types of comments....but the code should be re-written, it's a big pile of steaming noodles.

    EDIT: fixed some typo's, get real, you think I'm going to fix my grammer...sheez..what were you thinking????
    Last edited by Mick; January 20th, 2004 at 04:32 AM.

  6. #36
    Join Date
    Dec 2003
    Posts
    220
    Okay, Nina posted the quote like that because Nina actually also think it was the logic errors he made in his code. All of what Nina meant was it is not at the fopen and the if clause as you said. He said he was using VC++ compiler for his project, Nina also wrote the same code to test and it works fine, no logic problem as you pointed out....

  7. #37
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    Originally posted by Homestead
    Okay, Nina posted the quote like that because Nina actually also think it was the logic errors he made in his code. All of what Nina meant was it is not at the fopen and the if clause as you said. He said he was using VC++ compiler for his project, Nina also wrote the same code to test and it works fine, no logic problem as you pointed out....
    keep believing that.

  8. #38
    Join Date
    Dec 2003
    Posts
    220
    Originally posted by Mick
    would you like me to explain?

    first off what he posted as code snippets, and what he posted as the .zip are two different things, we could have been here all day, had the .zip not been posted.

    Lets take a look at what happens in the if clause.

    because of precedence the function fopen in the if clause gets executed first, it returns a valid handle and places it in file. It then test to see if file is null, this is false, it is valid, it will then JNE (jump if not equal) to the next clause the else if.

    It will again, execute the fopen, and push a NEW file handle into file, we now have two file handles open to the same file, one of which is 'dangling' it then tests if the file handle is not null, it isn't so we drop into the block and execute the stat etc.

    the remove(...) will fail as there is still an open file handle.

    though I normally don't make these types of comments....but the code should be re-written, it's a big pile of steaming noodles.

    EDIT: fixed some typo's, get real, you think I'm going to fix my grammer...sheez..what were you thinking????
    I absolutely agree with you tat he should change the WAY he wrote his code for its readability..
    I just wanted you to remember that we always want to make it clean and please dont make it worse or dirtier...
    I hope you understand that...

  9. #39
    Join Date
    Nov 2003
    Posts
    19
    Hi, I couldn't see what is wrong with logic.
    Could you please explain to me?

    That is the codes which was written by someone and I am just using it. When this codes was run in someone else application, I could delete the files manually although the application is still opened.

    However if I copy the codes into my application, I couldn't delete the file at all, if my application is running.

    But I think I have to give up on this.

    I am sorry for bugging you two with the messy codes.
    Thank You so much for helping.

  10. #40
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Okay guys...can we (again) stop the senseless 'I have right, you do not' thingie, that is going on here...and get back to the topic of getting the problem solved?

    Thank you very much.

  11. #41
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    Code:
    15:       if ((fp = fopen((char*)filename,"r")) == NULL)
    00401045   push        offset string "r" (00421058)
    0040104A   mov         eax,dword ptr [ebp+8]
    0040104D   push        eax
    0040104E   call        fopen (004017b0)
    00401053   add         esp,8
    00401056   mov         dword ptr [ebp-4],eax
    00401059   cmp         dword ptr [ebp-4],0
    0040105D   jne         funk+41h (00401061)
    16:       {
    17:
    18:       }
    19:
    20:       else if ((fp = fopen( (char *)filename,"r")) != NULL)
    0040105F   jmp         funk+62h (00401082)
    00401061   push        offset string "r" (00421058)
    00401066   mov         ecx,dword ptr [ebp+8]
    00401069   push        ecx
    0040106A   call        fopen (004017b0)
    0040106F   add         esp,8
    00401072   mov         dword ptr [ebp-4],eax
    00401075   cmp         dword ptr [ebp-4],0
    00401079   je          funk+62h (00401082)
    21:       {
    22:           int gothere = 0;
    0040107B   mov         dword ptr [gothere],0
    23:       }
    Last edited by Mick; January 20th, 2004 at 12:17 PM.

  12. #42
    Join Date
    Nov 2003
    Posts
    19
    Hi,

    Mick is right. There is something wrong with the logic.
    I commented out the lines, and the files get deleted without
    any problem!

    Thank You everyone!
    ^^

Page 3 of 3 FirstFirst 123

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured