[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 2 Applesoft BASIC questions/1 Hyper C question



In article <2t532a$1cc9@info2.rus.uni-stuttgart.de>,
Wulf Hofbauer <zcaa1122@rpool9.rus.uni-stuttgart.de> wrote:
>Try this one:

>main()
>{
>    FILE a; /* HyperC doesn't need pointers, though they won't matter */
>    a=create("THISFILE");
>    puts(a,"Hello world!\n");     /* much faster than fprintf */
>    close(a); /* not closing a file isn't very friendly */
>}

I did; it worked.

>The documentation I have says clearly that create() returns the
>ProDOS file descriptor, and -1 means failure (or 0 if you're using Opix).

>Of course not. Your use of create() could possibly crash the entire system
>as you pass an uninitialized pointer to create() where it expects a pointer
>to the pathname string. You could hit a softswitch accidentally, which is
>likely to be desastrous.

Not according to the documentation I have:

BOOL create(file, filename, filetype)   /*create a new file*/
FILE *file;
TEXT *filename;
INT  filetype

Create a file by the indicated name and type using the specified file control
block.  If the file already exists, it is truncated to zero blocks.  Future
access to the file in the program will be though this control block.  If the
file could be created the routine returns a non-zero value.  If the could not
be created, it returns zero.

The filename must be a valid filesystem name of 1 to 13 characters, optionally
preceeded by a drive prefix of a: or b:.  It should be a null terminated C
string.

The filetype code is not really used by anything in the system except the
directory lister.  It is merely informational.  Values may be selected from
the enumeration type defined in std.h as TEXTFILE, CODEFILE, DATAFILE, or
PICTFILE. The type VOLFILE is reserved for the volume name entry.  Any other
types will appear as a type code of '?' on a directory listing.

Example:
     FILE myfile;
     ...
     if(!create(myfile, "work#1, DATAFILE))
     {
          printf("Error opening work#1\n");
          exit(ERR);
     }
     ...

I'm using a copy of HyperC I downloaded about three years ago, so maybe the
I/O function syntax has changed since then, but I'd still expect the
documentation at the time to describe the program it came with accurately.
Incidentally, there was no DATAFILE, TEXTFILE, or any of those enumeration
types defined in my std.h.  I just picked zero because the docs said the
number didn't matter.

>Your code won't make sense under any I/O library, btw. You pass the pointer
>a to create() by value, not by reference. That is, the contents of the
>variable a can't be affected by create()!

D'oh!  I'm so used to writing file=fopen() that when I moved it inside the
parentheses, I neglected to add the &.  I was confused by the discrepancy
between the function prototype (which expects a pointer to a FILE struct)
and the form of the function given in the example (which takes the struct
itself).  What the heck is up with these docs?

>Take a look at the sample code provided with HyperC - it's an excellent
>example of how to access files.

The only code that came with my package that has anything to do with files
is "list", and that uses open(), not create().

------------------------------------------------------------------------------
"Guess again, Dr. Lu! Your plot flopped! Fizzled! Because of YOU!"
"Im-impossible! You were brainwashed! HOW could *I* fail?"  | smmcafee@mtu.edu
"Because you're a SCIENTIST who FORGOT she's ALSO a WOMAN!" |      Sean McAfee
                                 -- from "The Flash" #200, 9/70