Pelles C > General discussions

File Open Error - A Head Scratcher

(1/4) > >>

tony74:
OK, I've got a head-scratcher.
I saved this webpage to my drive: https://www.reddit.com/r/FREEMEDIAHECKYEAH/wiki/video/
It's a 677k .htm file on the local drive.

I attempt to open it like this:

--- Code: ---    if((fp=fopen(infile,"rb"))==NULL)
        return ERR;

--- End code ---
And it errors out immediately, won't even try to open.

Now, if I take out everything down to line 3157 (the start of the links list) in the .htm file, it opens just fine and the rest of the program runs without error.

I've never run into this before, a file open error that goes away when 3k lines are deleted from the file.
How does what's in a file cause it to fail to even open?
I'm not even processing anything yet, this is the first thing that happens in the program (beside checking args).
I've opened a lot bigger files that this without problems.
Definitely a new one for me!

I haven't tried it in gcc or VS yet.
I'm running Pelles 11.00.2

Any ideas?

algernon_77:
Hello,

I wasn't able to reproduce the behaviour, but I'm using Pelle 10.
I tried the following code...


--- Code: ---#include <stdio.h>
#include <stdlib.h>

int main ( int argc, char ** argv )
{
    FILE * fp;

    if (( fp = fopen ( "video - FREEMEDIAHECKYEAH.htm", "rb" )) == NULL )
    {
        fprintf ( stderr, "UNABLE TO OPEN\n" );
        return 1;
    }

    fprintf ( stderr, "SUCCESS !!!\n" );
    fclose (fp);

    return 0;
}

--- End code ---

...and it worked.

So I dunno :)
The only thing appearing to be "special" about that file is that it was saved as a html file from the browser, so it has a "filename_files" folder associated (they're managed as a pair by the shell). But I renamed both of them and it still works. Maybe try saving the file under a different name?
 

TimoVJL:
Is filename in ANSI format ?

John Z:
Hi Tony74

I suspect you have a problem elsewhere giving you a false lead.
I downloaded the exact file in your post and used the code below - no problem.

--- Code: --- char infile[256]={0};
sprintf(&infile[0],"%s","C://Users/John/Downloads/Tester/video - FREEMEDIAHECKYEAH.htm");
FILE *fp;
    if((fp=fopen(infile,"rb"))==NULL)
      {  MessageBoxA(NULL,"BAD","Filecheck",MB_OK);
return;}
    else
  { fclose(fp);
MessageBoxA(NULL,"OK","Filecheck",MB_OK);
}

--- End code ---
Said OK every time.  Then I added a z to the filename and it said BAD, remove the z then OK.

John Z

Pelles C 11 on Windows 11 btw....

Also check your file size "677" or is it 657?  See attached file size picture (typo or maybe yours is corrupt in some way). Does your browser open it?

Another possibility is your antivirus is blocking access because of a flag on the file.  When you edit the file the flag could be removed.  Look at file properties and check the unblock box and try again.  It was not necessary to do on my system but maybe it is on yours.  See third attachment.

tony74:
OK, it's something on my end. Have no idea what, at this point.
 
I re-downloaded the web page as:
fmhy.htm, from firefox-developer 111.0b8 (64 bit)
I'm on Win7 Pro SP1

Size:         674 KB (690,470 bytes)
Size on Disk: 676 KB (692,224 bytes)
I did click the 'unblock' button in file properties.

re-compiled in Pelles,  same error result.
re-compiled in VS2015,  same error result.
Debug build in VS2015,  error code 0x00000002.
compiled w/John's code, error 'BAD'.

--- Code: ---//john.c
////////////////////////////
#include <windows.h>
#include <stdio.h>

int main(int argc, char **argv)
{
    char infile[256]={0};
    FILE *fp;

    sprintf(&infile[0],"%s","C:\\mycollectedprogramming\\reddit3\\fmhy.htm");

    if((fp=fopen(infile,"rb"))==NULL){
        MessageBoxA(NULL,"BAD","Filecheck",MB_OK);
return 0;
    }
    else{
            fclose(fp);
            MessageBoxA(NULL,"OK","Filecheck",MB_OK);
     }

return 0;
}

--- End code ---
Attached a screenshot of debug build.

Navigation

[0] Message Index

[#] Next page

Go to full version