Mail Archives: djgpp/1998/04/18/18:57:39
Message-Id: | <3.0.5.32.19980418180634.00801320@pop.iquest.net>
|
Date: | Sat, 18 Apr 1998 18:06:34 +0500
|
To: | "John Doe" <treeman AT goodnet DOT com>, djgpp AT delorie DOT com
|
From: | Ricki Lee King <rlking AT iquest DOT net>
|
Subject: | Re: I need some help, I am having a hella of a time with
|
| Rhide...and DJGPP
|
In-Reply-To: | <01bd6af7$7ae2eb40$51878cd1@rihqdcee>
|
Mime-Version: | 1.0
|
i don't know what the exit code i get means but i think you
are trying to read past end of file. i don't feel like bending
my brain on the problem.
At 05:18 PM 4/18/98 GMT, John Doe wrote:
>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 -