Lots of room for improvement, error checking and clarity here,
but a hastily generated sketch of one basic approach would be:
/*
*
*/
typedef struct {
char *string;
unsigned long int token;
} stringMapPair;
stringMapPair pairMap[] = {
{ "string0", 0 },
{ "string1", 1 },
{ "string2", 2 },
{ "string3", 3 },
.
.
.
{ "stringN", N },
{ 0, ~0 },
};
/*
*
*/
unsigned long int
tokenForString(
char *string )
{
stringMapPair *pair;
pair = pairMap;
while( pair->string ) {
if( !strcmp( pair->string, string ) ) {
break;
}
++pair;
}
return( pair->token );
}
/*
*
*/
yourCode(
char *someString )
{
switch( tokenForString( someString ) ) {
case 0:
yadda, yadda, yadda...
break;
case 1:
yadda, yadda, yadda...
break;
case 2:
yadda, yadda, yadda...
break;
case 3:
yadda, yadda, yadda...
break;
.
.
.
.
case N:
yadda, yadda, yadda...
break;
case ~0:
couldn't match string, so reformat disk
break;
default:
theoretically not possible here, so reformat CDROM, too..
break;
}
}
**********************************************************
To unsubscribe from this list, send mail to
[EMAIL PROTECTED] with the following text in the
*body* (*not* the subject line) of the letter:
unsubscribe gnhlug
**********************************************************