okay then
int iGetIdForString(char *cmp_string)
{
weaponchar_id_t *comp_block;
int num = 0;
while((comp_block = WeaponCodes[num++]) != NULL)
{
if(strcmp(cmp_string,comp_block->cStringId) == 0)
return comp_block->iId;
}
return -1;
}
that should do it...
----- Original Message -----
From: "Mugsy _" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, May 06, 2002 11:54 PM
Subject: Re: [hlcoders] string to #define
> I need to go the other way, from string to int.
>
>
> >From: "Josh Coyne" <[EMAIL PROTECTED]>
> >Reply-To: [EMAIL PROTECTED]
> >To: <[EMAIL PROTECTED]>
> >Subject: Re: [hlcoders] string to #define
> >Date: Mon, 6 May 2002 23:52:26 -0400
> >
> >well with the string array you could just do like
> >
> >char *cGetStringForId(int iId)
> >{
> > weaponchar_id_t *comp_block;
> > int num = 0;
> >
> > while((comp_block = WeaponCodes[num++]) != NULL)
> > {
> > if(comp_block->iId == iId)
> > return comp_block->cStringId;
> > }
> > return NULL; // or return "" or whatever u want
> >}
> >
> >should give you an idea of what i mean by a list array
> >
> >----- Original Message -----
> >From: "Mugsy _" <[EMAIL PROTECTED]>
> >To: <[EMAIL PROTECTED]>
> >Sent: Monday, May 06, 2002 11:40 PM
> >Subject: Re: [hlcoders] string to #define
> >
> >
> > >
> > > Yeah I thought about that but I think it ends up with a lot of string
> > > compares. The particular method I am thinking of ( I might be
> >remembering
> > > some magical C++ dream I had ) acutally involved converting a string
> >into
> >a
> > > variable name directly.
> > >
> > > But I'm most likely on crack.
> > >
> > >
> > >
> > > >From: "Josh Coyne" <[EMAIL PROTECTED]>
> > > >Reply-To: [EMAIL PROTECTED]
> > > >To: <[EMAIL PROTECTED]>
> > > >Subject: Re: [hlcoders] string to #define
> > > >Date: Mon, 6 May 2002 23:25:33 -0400
> > > >
> > > >hmm
> > > >
> > > >a possible idea could be a string table maybe
> > > >
> > > >an array of string/code structs, like
> > > >
> > > >typedef struct
> > > >{
> > > > char cStringId[256];
> > > > int iId;
> > > >}weaponchar_id_t;
> > > >
> > > >then you could perhaps have like
> > > >
> > > >weaponchar_id_t WeaponCodes[] = {
> > > > { "WEAPON_GARAND",2 },
> > > > { "WEAPON_1911", 1},
> > > > NULL,
> > > > // etc
> > > >};
> > > >
> > > >then have a support function or two to grab the string/int and
compare
> >in
> > > >this array
> > > >this could be more work, who knows, but here it looks a bit easier to
> >just
> > > >reference similar items in an array
> > > >
> > > >----- Original Message -----
> > > >From: "Dynerman David M" <[EMAIL PROTECTED]>
> > > >To: <[EMAIL PROTECTED]>
> > > >Sent: Monday, May 06, 2002 11:10 PM
> > > >Subject: RE: [hlcoders] string to #define
> > > >
> > > >
> > > > > Well they say when you're not sure try..so I did and Leon's right
> >(at
> > > > > least with VC++)
> > > > >
> > > > > I'm not sure where I saw/read that it would scan quotes, but the
> >define
> > > > > didn't work for me (it would just print out WEAPON_GARAND instead
of
> >2)
> > > > >
> > > > > Looks like we're stuck defining string literals or numbers, but
not
> > > > > mixing & matching.
> > > > >
> > > > > david
> > > > >
> > > > > -----Original Message-----
> > > > > From: Leon Hartwig [mailto:[EMAIL PROTECTED]]
> > > > > Sent: Monday, May 06, 2002 9:50 PM
> > > > > To: '[EMAIL PROTECTED]'
> > > > > Subject: RE: [hlcoders] string to #define
> > > > >
> > > > > I'm sure it depends on which preprocessor is being used, but I
doubt
> > > > > most
> > > > > modern ones do this.
> > > > >
> > > > >
> > > > > > -----Original Message-----
> > > > > > From: Dynerman David M [mailto:[EMAIL PROTECTED]]
> > > > > > Sent: Monday, May 06, 2002 7:35 PM
> > > > > > To: [EMAIL PROTECTED]
> > > > > > Subject: RE: [hlcoders] string to #define
> > > > > >
> > > > > >
> > > > > > The pre-processors scan through source files replacing the
define
> >with
> > > > > > the value.
> > > > > >
> > > > > > I'm not 100% sure, but about 95% that it looks in strings as
well,
> >so
> > > > > >
> > > > > > someFuncThatTakesAString("WEAPON_GARAND");
> > > > > >
> > > > > > will get changed to
> > > > > >
> > > > > > someFuncThatTakesAString("2"); //constant string 2\0
> > > > > >
> > > > > > before its compiled.
> > > > > _______________________________________________
> > > > > To unsubscribe, edit your list preferences, or view the list
> >archives,
> > > > > please visit:
> > > > > http://list.valvesoftware.com/mailman/listinfo/hlcoders
> > > > >
> > > > > _______________________________________________
> > > > > To unsubscribe, edit your list preferences, or view the list
> >archives,
> > > >please visit:
> > > > > http://list.valvesoftware.com/mailman/listinfo/hlcoders
> > > > >
> > > >
> > > >_______________________________________________
> > > >To unsubscribe, edit your list preferences, or view the list
archives,
> > > >please visit:
> > > >http://list.valvesoftware.com/mailman/listinfo/hlcoders
> > >
> > >
> > > _________________________________________________________________
> > > Get your FREE download of MSN Explorer at
> >http://explorer.msn.com/intl.asp.
> > >
> > > _______________________________________________
> > > To unsubscribe, edit your list preferences, or view the list archives,
> >please visit:
> > > http://list.valvesoftware.com/mailman/listinfo/hlcoders
> > >
> >
> >_______________________________________________
> >To unsubscribe, edit your list preferences, or view the list archives,
> >please visit:
> >http://list.valvesoftware.com/mailman/listinfo/hlcoders
> >
>
>
> _________________________________________________________________
> Chat with friends online, try MSN Messenger: http://messenger.msn.com
>
> _______________________________________________
> To unsubscribe, edit your list preferences, or view the list archives,
please visit:
> http://list.valvesoftware.com/mailman/listinfo/hlcoders
>
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders