[A89] Re: files and AMS 2.05


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

[A89] Re: files and AMS 2.05




> I've upgraded to AMS 2.05, and after a minor struggle, everything seems
> to be working.  Except this:
> 
> <code>
> //open file and check for errors
> file_ptr = fopen("orbsave", "rb");
> if(ferror(file_ptr))
> {
> fclose(file_ptr);
> FontSetSys(F_6x8);
> clrscr();
> puts("\n\n\n\n\n\n   Error Opening File.");
> FontSetSys(F_4x6);
> GKeyIn(NULL, 0);
> return params;
> }
> </code>
> 
> The if statement doesn't execute if the file doesn't exist.  Instead the
> program crashes with a "protected memory violation" error when it tries
> to read from the file.  If the file does not exist, ferror() = FALSE; if
> the file exists, ferror() = FALSE.  This had no problems with AMS 1.00.

I have never used the file functions, I've just read the docs, so this
might not be the error, but (from the TIGCC docs on fopen()):
---
Note: All functions which accepts a parameter which is a pointer to a FILE
structure assumes that the pointer is valid, i.e. created using fopen
command. As I have no any efficient method to check whether the pointer is
valid or not, no checking is implemented. So, if you pass an invalid
pointer to any file handling function, the results are unpredictable. 
---

It also states that if an error occurs fopen() will return a NULL pointer.

--
 / Niklas Brunlid
Check out Prosit for the TI-89 / TI-92+ at http://prosit.ticalc.org
Random PQF v5.1 Quote follows:

He did of course sometimes have people horribly tortured to death, but this
was considered to be perfectly acceptable behaviour for a civic ruler and
generally approved of by the overhelming majority of citizens. [footnote:
The overhelming majority of citizens being defined in this case as everyone
not currently hanging upside down over a scorpion pit]
        -- (Terry Pratchett, Sourcery)






References: