delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/29/22:16:42

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Allegro Datafiles - More Problems
Date: Thu, 29 Jan 1998 19:28:48 +0000
Organization: None
Distribution: world
Message-ID: <xYFPyCAwhN00Ew$u@talula.demon.co.uk>
References: <MPG DOT f39e7cbc8b4c11d9896bd AT news>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
Lines: 37
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Matt Riker writes:
>First problem, is when I try and substitute a datafile object with a 
>variable.  Example:
>
>   draw_sprite(screen,datafile[spritename].dat,16,16);
>
>spritename is a char with a 20 character array, containing "BLANK".

An array index must always be an integer value, just like the compiler
error message is telling you. Change your spritename variable to an int,
and initialise it with the numeric value BLANK (which is a #defined
constant from the grabber header file), rather than the string "BLANK".

It sounds to me like you need to dig out a good C book and do some
reading about the differences between integers, arrays, and string data!

>Second problem: having 2 datafiles opened at the same time.
[...]
>   strcpy(get_filename(buf), "c:/maped/testspr.dat");
>   user_datafile = load_datafile(buf);

Why make life so complicated for yourself? Since you are using a 
fully-qualified path, just pass "c:/maped/testspr.dat" directly to the
load_datafile() call. That more complex code, which I presume you copied
from one of the Allegro utilities, is intended to handle files from
different directories, and won't work if you are directly supplying a
full path to the file. Assuming you have initialised the buffer to an
empty string, the first time you run this code it will just be changed
to the name of your file, but on a subsequent execution the filename of
the original path will be replaced by the new string, giving something
like "c:/maped/c:/maped/testspr.dat", which is not at all what you
want...


--
Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
"Pigs use it for a tambourine" - Frank Zappa

- Raw text -


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