delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/18/13:33:25

From: "John Doe" <treeman AT goodnet DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: I need some help, I am having a hella of a time with Rhide...and DJGPP
Date: 18 Apr 1998 17:18:38 GMT
Organization: GoodNet
Lines: 147
Message-ID: <01bd6af7$7ae2eb40$51878cd1@rihqdcee>
NNTP-Posting-Host: d6-16.phoenix.goodnet.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Okay now, I have been using the DJGPP compiler with rhide ever since I
downloaded DJGPP. Nothing has failed me, (but then again, no really big
programs...) I am wrtting this game, and in order to load up some data, I
need to store it in a file of record. (or structers...) Now, I have written
3 demo programs to see why MOST of the time Rhide crashes. I thought it was
from me, and maybe I was making some little syntax
mistake. No, it doesn't appear that way. I am getting every frustrated with
this, but I am asking for some assistance. Here are are 2 programs I have
written, to test rhide and see if it is ride it self or if its djgpp.
Most of the time they DON'T work, but if I run the same program 2 times in
a row, it works fine... :(

--- cut --- filetst.c ------

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>


// before running this program, create a text file called 'test.txt'
// and put in  2 integers on 2 diffrant lines, then a string value.
// like so:


// 100
// 100
// blahblahblah

struct blah {
   int x, y;
   char *name;
};
struct blah *testing;
main () {
   FILE *fp;


   testing->name = " ";
   printf("\n\nReading straight from text file.\n\n ");
   if ((fp = fopen("test.txt", "r")) != NULL) {
      fscanf(fp, "%d", &testing->x);
      fscanf(fp, "%d", &testing->y);
      fscanf(fp, "%s", testing->name);
      fclose(fp);
      printf("%d-%d-%s", testing->x, testing->y, testing->name);
   }
   else {
      printf("not able to open file.\n");
      return(0);
   }
   printf("\n\nWritting straight to binary file.\n\n ");
   if ((fp = fopen("test.out", "wb")) != NULL) {
      fwrite(testing, sizeof(testing), 1, fp);
      fclose(fp);
   }

   testing->name = " ";
   printf("\n\nReading straight from binary file.\n\n ");
   if ((fp = fopen("test.out", "rb")) != NULL) {
      fread(testing, sizeof(testing), 1, fp);
      fclose(fp);
      printf("%d-%d-%s", testing->x, testing->y, testing->name);
   }

}





--- here is the second program that isn't working. ---




#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <allegro.h>


// this program requires a text file named 'in.obj'. the text file should
contain the following
// to be able to load the file correctly. it firstly contains the name of
the object,
// a number telling if it is an animation, (0 or 1,) then a frame number,
then the list of
// bitmap files...



// grass1
// 1
// 3
// grass1.bmp
// grass2.bmp
// grass3.bmp

struct object_type {   // our obj record
   char *name;         // the name of the obj
   int animation,      // 0 if not animation 1 if it is an animation
       frame_count,    // number of frames
       adj;            // ajusting value, or temp value
   BITMAP *frames[5];  // our bitmaps if more then one
   char *pic_names[5]; // the names of the bitmaps that will be loaded
};

struct object_type *temp;

main () {
   FILE *fp;
   int loop;

   temp->name = " ";
   printf("\n\nLoading from 'IN.OBJ', and outputting to 'OBJECTS.DAT'\n");
   printf("If 'OBJECTS.DAT' already exist, it will be appended to, if
it\n");
   printf("doesn't exist, it will be created. ");

   if ((fp = fopen("IN.OBJ", "r")) != NULL) {
      fscanf(fp, "%s", temp->name);
      fscanf(fp, "%d", &temp->animation);
      fscanf(fp, "%d", &temp->frame_count);
      for (loop=0; loop<=temp->frame_count; loop++){
         fscanf(fp, "%s", temp->pic_names[loop]);
      }
      fclose(fp);
   }
   else {
      printf("\n\nNOT ABLE TO OPEN 'IN.OBJ'\n\n\n");
      return(0);
   }
   if ((fp = fopen("OBJECTS.DAT", "a+")) != NULL) {
      printf("\nWRITTING...");
      fwrite(temp, sizeof(temp), 1, fp);
      fclose(fp);
      printf(" DONE...\n\n");
   }
   else {
      printf("\n\nNOT ABLE TO CREATE/APPEND 'OBJECTS.DAT'\n\n\n");
      return(0);
   }
}




- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019