Mail Archives: djgpp/1999/04/19/17:25:47
From: | vern <vern AT iocc DOT com>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | writing to a file
|
Date: | Mon, 19 Apr 1999 16:57:08 -0500
|
Organization: | Posted via RemarQ Communities, Inc.
|
Lines: | 173
|
Message-ID: | <371BA6B3.E5FF77BB@iocc.com>
|
NNTP-Posting-Host: | 204.214.235.110
|
NNTP-Posting-Date: | Mon, 19 Apr 1999 22:01:27 GMT
|
X-Trace: | 924559287.313.47 Z.MU6KIEIEB6ECCD6C usenet1.supernews.com
|
X-Complaints-To: | newsabuse AT remarQ DOT com
|
X-Mailer: | Mozilla 4.51 [en] (WinNT; I)
|
X-Accept-Language: | en
|
MIME-Version: | 1.0
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
hi, im having trouble wrintg some variables to a file. I'm using hte
latest version of DJGPP and allegro. My program compiles ok, but it
isnt working right. I put a zillion if statements that output "ERROR!"
whenever something goes wrong, to try to see whats going on. I can open
the file successfully, but I cannot write to it. I am trying to write
the following ot the file: an array of BITMAPS (if u havent used
allegro, a bitmap is a typedef structure), and an array of structures.
here is my code:
#include <stdio.h>
#include <allegro.h>
#include <iostream>
using namespace std;
FILE* save_file;
BITMAP* tile_bmps[2]; //array of all the tile bmps
typedef struct TILE //basic tile struct
{
int bmp_number; //the element number for htis tiles bitmap
int walkable; //whether this tile can be walked on-0=yes, 1=no,
else=special
int special; //any special characteristics the tile has
int extra; //extra stuff things might need: whether a door is
open/closed
} TILE;
TILE map[10][10]; //the map, consisting of 100 tile structs.
void draw_tile_bitmaps(void);
void set_up_map(void);
void write_map_to_file(void);
int main()
{
cout << "Initializing...";
allegro_init();
cout << "Done.\n";
cout << "Drawing tile bitmaps...";
draw_tile_bitmaps();
cout << "Done.\n";
cout << "Creating map...";
set_up_map();
cout << "Done.\n";
cout << "Writing to file demo.map...";
write_map_to_file();
cout << "Done.\n";
cout << "Finished! Shutting down...";
allegro_exit();
cout << "Done.\n";
return 0;
}
void draw_tile_bitmaps(void)
{
int x=0, y=0;
//create the bmps & clear em.
tile_bmps[0] = create_bitmap_ex(8, 32, 32);
tile_bmps[1] = create_bitmap_ex(8, 32, 32);
clear(tile_bmps[0]);
clear(tile_bmps[1]);
//print soem stuff onto em.
//first tile
for(x=0; x<33; x++)
putpixel(tile_bmps[0], x, x, 50);
x = 32;
for(y=0; y<33;y++)
{
putpixel(tile_bmps[0], x, y, 25);
x--;
}
//second tile.
rectfill(tile_bmps[0], 0, 0, 32, 32, 150);
//and thats it!
}
void set_up_map(void)
{
int y=1;
//set the edge to all walls
for(int x=0;x<10;x++)
{
map[0][x].bmp_number = 0;
map[0][x].walkable = 1;
map[0][x].special = 0;
map[0][x].extra = 0;
}
for(int x=0;x<10;x++)
{
map[10][x].bmp_number = 0;
map[10][x].walkable = 1;
map[10][x].special = 0;
map[10][x].extra = 0;
}
for(int x=1;x<9;x++)
{
map[x][0].bmp_number = 0;
map[x][0].walkable = 1;
map[x][0].special = 0;
map[x][0].extra = 0;
}
for(int x=1;x<9;x++)
{
map[x][10].bmp_number = 0;
map[x][10].walkable = 1;
map[x][10].special = 0;
map[x][10].extra = 0;
}
//fill the inside
for(y=1;y<9;y++)
{
for(int x=1;x<9;x++)
{
map[x][y].bmp_number = 1;
map[x][y].walkable = 0;
map[x][y].special = 0;
map[x][y].extra = 0;
}
y++;
}
}
void write_map_to_file(void)
{
int test;
cout << "Opening File...";
save_file = fopen("demo.map", "w");
if(save_file==NULL)
{
cout << "ERROR!" << save_file;
}
cout << "Done.\n";
cout << "Writing ot File..."; //errors start AFTER this
point.
//write the list of bmps
test = fwrite(tile_bmps, sizeof(tile_bmps), 1, save_file);
if(test!=sizeof(tile_bmps)) cout << "ERROR!" << test; //error
here
//write the map struct
test = fwrite(map, sizeof(map), 1, save_file);
if(test!=sizeof(tile_bmps)) cout << "ERROR!" << test; //error
here.
cout << "Done.\n";
}
The error is occuring just after it opens the file, and tries to write.
It opens the file successfully, then gives me 2 error messages. Ive
spent some time trying to figure this out myself, but no luck.
Thanks,
Andy F.
- Raw text -