#include <stdio.h>
#include <stdlib.h>
/* read_bstring - read a string from a BASIC-format file and place in str */
/* by D McSweeney */

char *read_bstring(FILE *in, char *str)
{
int n;                 /** to receive input (fgetc returns an int) **/

n=fgetc(in);           /** zero **/
n=fgetc(in);           /** string length **/

str[n--]='\0';           /** insert terminator **/

while(n >= 0 && !feof(in) && !ferror(in))
   *(str + n--) = fgetc(in);

if(n == -1)    /** valid exit from 'while': '==' is 'IS EQUAL TO' **/
   return(str);
else
   return(0);

}

/* read and display a file full of BASIC-format strings */
/* by D McSweeney */

int main()
{
FILE *in;
char *sp,b_string[256];

in=fopen("BStrings", "r");
if(!in){
   printf("Can't open the file!\n");
   exit(1);
   }

while((sp=read_bstring(in, b_string)))
   printf("%s\n", b_string);

if(!feof(in))
   printf("Some sort of file error, I'm afraid... ");

fclose(in);
printf("That's yer lot!\n");
}


