delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/13/14:16:34

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: still having datafile problems with allegro
Date: Mon, 13 Apr 1998 11:28:45 +0100
Organization: None
Message-ID: <ojp9CuAdjeM1EwKR@talula.demon.co.uk>
References: <1998041301343800 DOT VAA00817 AT ladder01 DOT news DOT aol DOT com>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
Lines: 31
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

TackMast writes:
>strcpy(buf, get_filename("c:\djgpp\bin\game.dat"));

This is garbage, for several reasons. In C, \ is the string escape
character, so you can't use it in string literals. Either use a double
\\, or / style slashes. btw. this line will cause some compiler warnings
about \d and \g being invalid escape sequences. Pay attention to these:
if the compiler warns you about something, it is probably a good idea to
fix it!

More generally, why are you doing this in such an overcomplicated way?
Calling get_filename() on a constant string is pointless: why not just
write "game.dat"? And why go to all the trouble of copying this into a
temporary array, when you could just pass it directly to
load_datafile()?

>data = load_datafile(buf);

Check for errors. This call might fail: if so you need to detect that,
print a warning, and abort the program.

>set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0);

Again, check for errors. If you just go around calling functions and
assuming that everything will always succeed, you have no way to tell
where the problem is when one of these calls fails to work correctly.


--
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