1753873 Members
7459 Online
108809 Solutions
New Discussion юеВ

C fopen

 
Bojan Nemec
Honored Contributor

C fopen

Hi,

Can anyone explain me the behavior of the C fopen function?

There is what I mean:

A short C program:
#include
int main ()
{
FILE * f;
f = fopen ("A.TMP","w");
fclose (f);
return 1;
}

I run this program and if I do a directory/full I get:
.
.
Record format: Stream_LF, maximum 0 bytes, longest 32767 bytes
.
.

Then I type:
$ create a.tmp


The dir/full gives me:
.
.
Record format: Variable length, maximum 0 bytes, longest 0 bytes

Ok, another run of the program and dir/full gives me:
.
.
Record format: Variable length, maximum 0 bytes, longest 0 bytes

This means that the record format is obtained from the previous version of the file!

Regards
Bojan
4 REPLIES 4
Martin Vorlaender
Honored Contributor

Re: C fopen

>
This means that the record format is obtained from the previous version of the file!
<

This is documented behaviour, see
http://h71000.www7.hp.com/commercial/c/docs/5763p027.html#fopen_routine

cu,
Martin
Bojan Nemec
Honored Contributor

Re: C fopen

Thank you,

I will modify my programs to force the attributes. Another #ifdef __VMS.


Bojan
Martin P.J. Zinser
Honored Contributor

Re: C fopen

Hello Bojan,

one way to minimize this particular ifdef

#ifdef VMS
#define FOPEN_OPT ...
#else
#define FOPEN_OPT ...
#endif

then use the FOPEN_OPT macro in the actual
fopen calls without any ifdefs. This also has the adavantage that if you decided you need to twiddle yet another knob the change is very well localized.

Greetings, Martin