delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/04/11:46:56

From: Gruber Gerhard <g DOT gruber AT sis DOT co DOT at>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Allegro Datafiles - More Problems
Date: Wed, 04 Feb 1998 16:49:52 +0100
Organization: APAnet
Lines: 43
Message-ID: <34D88E20.5056175E@sis.co.at>
References: <C125659B DOT 002E50AC DOT 00 AT vega DOT ads DOT it> <MPG DOT f3a8f8ba7e93c3a9896be AT news>
NNTP-Posting-Host: 192.56.14.75
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Matt Riker wrote:

>  > the 'spritename' must be an int containing BLANK. If you need to use
>  > different
>  > values assign different ints to spritename.
> 
> I could be just dumb :), but how can you but a string of letters into an
> int?

You should use another array where the names are stored and then use the
index.
You could do it like this for example:

char *spritenames[4] = {
  "SPR1", 
  "SPR2", 
  "SPR3", 
  NULL
};

int foo(char *name)
{
   int i;

   for(i = 0; spritenames[i] != NULL; i++)
   {
      if(strcmp(spritenames[i], name) == 0)
          return(i);
   }

   return(-1);
}
  
Now you know the index of the spritename and can use it to index into
your datafile array.
-- 

Bye,
   Gerhard

email: gruber2 AT ibm DOT net
       g DOT gruber AT sis DOT co DOT at
FIDO:  Gruber_Gerhard AT 2:310/81.11

- Raw text -


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