Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SWIs and BASIC file reading/writing in C++ (reply to #86

0 views
Skip to first unread message

Jonathan Graham Harston

unread,
Oct 21, 2009, 5:32:32 PM10/21/09
to
Jonathan Graham Harston of fidonet#2:250/3 wrote:
> garethlock wrote:
> > I understand the command side of things, but I need to be able to
> > convert files written with BASICs PRINT# command. That is why I need
> > either customised routines to do it, or how BASIC does it, so I can
>
> Otherwise, I could through some C code together to add to the VB
> implementation.

Ok, will http://mdfs.net/Info/Comp/BBCBasic/ProgTips do?

--
J.G.Harston - j...@arcade.demon.co.uk - mdfs.net/User/JGH
Whitby Yards Gazetteer - http://mdfs.net/Docs/Books/YofWhitby/Gazetteer

jeff

unread,
Oct 22, 2009, 3:07:25 AM10/22/09
to
> Jonathan Graham Harston of fidonet#2:250/3 wrote:
> Ok, willhttp://mdfs.net/Info/Comp/BBCBasic/ProgTipsdo?

Difficult to say as the BBCFile and BBCFile.c links both 404

Jeff

Jonathan Graham Harston

unread,
Oct 22, 2009, 7:05:57 PM10/22/09
to
> Difficult to say as the BBCFile and BBCFile.c links both 404

Doh! I'd uploaded it as BBCFiile.c ! Blame 12-point Trinity ;)A Review of Sheffield City Council's Members' Allowances Scheme
See http://mdfs.net/payreform

jeff

unread,
Oct 23, 2009, 3:20:55 AM10/23/09
to
> Jonathan Graham Harston of fidonet#2:250/3 wrote:
> Ok, willhttp://mdfs.net/Info/Comp/BBCBasic/ProgTipsdo?

In file BBCFile.c:

Function void bbc_WrStr(FILE * handle, char *str) won't work.

You've muddled up | and || in the function bbc_RdInt()
You've missed out the '*' in all of the handles.
In the function "int bbc_RdStr(FILE handle)" you've forgotten to put
the NULL terminator on the end of the string and to allow for it
in the malloc. A common error by C newbies. Plus the off-by-one error
as well.
You've also made the common error of declaring unsigned numbers as
signed (e.g. val in the same function - a string length can never be
negative so why use a signed number?)
And finally you've used malloc() without checking for the NULL return
code.


char * bbc_RdStr (FILE * handle)
{
unsigned int val;
char *str;
char *p;

val = fgetc (handle);
if (val != 0)
return (NULL); /* Not a string in the data-stream */

val = fgetc (handle);
str = malloc (val + 1); /* One extra for the string terminator */
if (str == NULL) /* NEVER use malloc without checking
for the out-of-memory condition */
return (NULL);

p = str + val;
*p-- = 0; /* Terminate the string with a null */

if (val) /* Anything to copy? */
{
do
{
*p-- = fgetc (handle);
} while (--val);
}

return (str);
}

Jeff

Jonathan Graham Harston

unread,
Oct 24, 2009, 12:51:12 PM10/24/09
to
jeffrey....@gmail.com wrote:
> > Jonathan Graham Harston of fidonet#2:250/3 wrote:
> > Ok, willhttp://mdfs.net/Info/Comp/BBCBasic/ProgTipsdo?
>
> In file BBCFile.c:

[Snip list of mistakes]

Ta. I threw the initial code togther from memory. I also have a
nagging feeling that WrReal and RdReal probably won't work as they
assume that the compiled C program is holding reals in memory
identically to BASIC. They probably need to explicitly calculate
the values.The most perfect world is an imperfect world as the imperfections
give people a reason to strive to change it.
0 new messages