Can't Read File Unless I Change File Name 
Author Message
 Can't Read File Unless I Change File Name

With a Win2K console app I've written, I was unable to open for
reading a binary file with the name of

a7e5-b212.bin

No other app had the file already open, and editors were able to read
it fine. But if I renamed it using an underscore to

a7e5_b212.bin

it opened and read fine.

But, previously I was able to read files (such as a7cd-a7d0.bin) that
*did* contain a dash.

Just curious.

Simon.

Code used:

pReadFile = fopen(pReadFileName, "r+b");
if (pReadFile == NULL)
{
    printf("Could not open file to read\n");
    return (1);

Quote:
}

[MESSAGE END]


Tue, 09 Nov 2004 03:15:54 GMT  
 Can't Read File Unless I Change File Name

Quote:

> With a Win2K console app I've written, I was unable to open for
> reading a binary file with the name of

> a7e5-b212.bin

> No other app had the file already open, and editors were able to read
> it fine. But if I renamed it using an underscore to

> a7e5_b212.bin

> it opened and read fine.

Sounds like an OS-specific problem.  The C standard doesn't say
anything about it.  Maybe you should ask in a Windows group?

Quote:
> [MESSAGE END]

Thanks for the hint.  If you hadn't let me know that the message
was ending, I might have kept reading forever just in case there
was more to come.
--
"It would be a much better example of undefined behavior
 if the behavior were undefined."
--Michael Rubenstein


Tue, 09 Nov 2004 03:21:00 GMT  
 Can't Read File Unless I Change File Name

Quote:
>With a Win2K console app I've written, I was unable to open for
>reading a binary file with the name of

>a7e5-b212.bin

>No other app had the file already open, and editors were able to read
>it fine. But if I renamed it using an underscore to

>a7e5_b212.bin

>it opened and read fine.

hence your code is fine but the underlying implementation or o/s is doing
something (perhaps buggy).  probably you'll be best served by posting to a
group supporting your compiler and/or ms-windows.

--
bringing you boring signatures for 17 years



Tue, 09 Nov 2004 06:58:06 GMT  
 Can't Read File Unless I Change File Name

Quote:
>With a Win2K console app I've written, I was unable to open for
>reading a binary file with the name of

>a7e5-b212.bin

>No other app had the file already open, and editors were able to read
>it fine. But if I renamed it using an underscore to

>a7e5_b212.bin

>it opened and read fine.

>But, previously I was able to read files (such as a7cd-a7d0.bin) that
>*did* contain a dash.

You don't have a C question: the C standard doesn't specify what is a
valid file name and what isn't.

comp.os.ms-windows.programmer.win32 is the right place for your question.

Dan
--
Dan Pop
DESY Zeuthen, RZ group



Tue, 09 Nov 2004 17:36:40 GMT  
 Can't Read File Unless I Change File Name
On 23 May, in article


Quote:
>With a Win2K console app I've written, I was unable to open for
>reading a binary file with the name of

>a7e5-b212.bin

>No other app had the file already open, and editors were able to read
>it fine. But if I renamed it using an underscore to

>a7e5_b212.bin

>it opened and read fine.

>But, previously I was able to read files (such as a7cd-a7d0.bin) that
>*did* contain a dash.

>Just curious.

>Simon.

>Code used:

>pReadFile = fopen(pReadFileName, "r+b");
>if (pReadFile == NULL)
>{
>    printf("Could not open file to read\n");
>    return (1);
>}

The code is fine as far as C is concerned, as far as it goes. You haven't
provided enough context to prove that pReadFileName is really a pointer
to the file name you indicated. At the very least output the file name
in the printf() call so you can visually verify it.

While it isn't guaranteed errno is often set by file operations so it
might be worth checking the value of errno after the call and along with
perror() or strerror() you might get a hint as to what the problem is.

Failing that try creating a minimal but complete program that demonstrates
the problem. As things stand you may have a bug somewhere else in your
program that is corrupting something used here. Or maybe you have
a platform-specific problem like read-only permissions on the file.

--
-----------------------------------------


-----------------------------------------



Fri, 12 Nov 2004 00:33:49 GMT  
 Can't Read File Unless I Change File Name

Quote:

> On 23 May, in article


>>With a Win2K console app I've written, I was unable to open for
>>reading a binary file with the name of

>>a7e5-b212.bin

>>No other app had the file already open, and editors were able to read
>>it fine. But if I renamed it using an underscore to

>>a7e5_b212.bin

>>it opened and read fine.

>>But, previously I was able to read files (such as a7cd-a7d0.bin) that
>>*did* contain a dash.

>>Just curious.

>>Simon.

>>Code used:

>>pReadFile = fopen(pReadFileName, "r+b");
>>if (pReadFile == NULL)
>>{
>>    printf("Could not open file to read\n");
>>    return (1);
>>}
> The code is fine as far as C is concerned, as far as it goes. You haven't
> provided enough context to prove that pReadFileName is really a pointer
> to the file name you indicated. At the very least output the file name
> in the printf() call so you can visually verify it.
> While it isn't guaranteed errno is often set by file operations so it
> might be worth checking the value of errno after the call and along with
> perror() or strerror() you might get a hint as to what the problem is.
> Failing that try creating a minimal but complete program that demonstrates
> the problem. As things stand you may have a bug somewhere else in your
> program that is corrupting something used here. Or maybe you have
> a platform-specific problem like read-only permissions on the file.
> --
> -----------------------------------------


> -----------------------------------------

You may want to enclose your filename in double quotes.

Adam



Thu, 25 Nov 2004 03:40:22 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Can't open database file unless filed count matches

2. copy a file if it's name had been change

3. Reading a file name from a text file

4. File->New in doc/view doesn't clear doc file name

5. How to read file while it's opened as a file number in VB

6. Beginner [Q] Using Canned File Open/Save dialog

7. .def files and 'company name'

8. Abbreviated '...' file names

9. 'Program Files' dir name

10. CFile can't read file's update lie in novell

11. Change file -> change timestamp of file

12. Problems reading '13' from file

 

 
Powered by phpBB® Forum Software