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