E
Eirik WS
Is there a more efficient way of comparing a string to different words?
I'm doing it this way:
if(strcmp(farge, "kvit") == 0)
peikar_til_glas_struktur->farge = KVIT;
if(strcmp(farge, "raud") == 0)
peikar_til_glas_struktur->farge = RAUD;
if(strcmp(farge, "blå") == 0)
peikar_til_glas_struktur->farge = BLAA;
if(strcmp(farge, "gul") == 0)
peikar_til_glas_struktur->farge = GUL;
if(strcmp(farge, "grøn") == 0)
peikar_til_glas_struktur->farge = GROEN;
if(strcmp(farge, "rosa") == 0)
peikar_til_glas_struktur->farge = ROSA;
if(strcmp(farge, "svart") == 0)
peikar_til_glas_struktur->farge = SVART;
if(strcmp(farge, "med mønster") == 0)
peikar_til_glas_struktur->farge = MED_MOENSTER;
if(strcmp(farge, "indigo") == 0)
peikar_til_glas_struktur->farge = INDIGO;
if(strcmp(farge, "lilla") == 0)
peikar_til_glas_struktur->farge = LILLA;
Don't worry if you don't understand the variable names. It's
irrelevant. You get the point anyway.
I was wondering if maybe I could use the switch statement,
but I have to compare each colour to the string, and I can't do
that in a switch statement, can I?
Thanks for any help.
I hope this isn't off-topic.
I'm doing it this way:
if(strcmp(farge, "kvit") == 0)
peikar_til_glas_struktur->farge = KVIT;
if(strcmp(farge, "raud") == 0)
peikar_til_glas_struktur->farge = RAUD;
if(strcmp(farge, "blå") == 0)
peikar_til_glas_struktur->farge = BLAA;
if(strcmp(farge, "gul") == 0)
peikar_til_glas_struktur->farge = GUL;
if(strcmp(farge, "grøn") == 0)
peikar_til_glas_struktur->farge = GROEN;
if(strcmp(farge, "rosa") == 0)
peikar_til_glas_struktur->farge = ROSA;
if(strcmp(farge, "svart") == 0)
peikar_til_glas_struktur->farge = SVART;
if(strcmp(farge, "med mønster") == 0)
peikar_til_glas_struktur->farge = MED_MOENSTER;
if(strcmp(farge, "indigo") == 0)
peikar_til_glas_struktur->farge = INDIGO;
if(strcmp(farge, "lilla") == 0)
peikar_til_glas_struktur->farge = LILLA;
Don't worry if you don't understand the variable names. It's
irrelevant. You get the point anyway.
I was wondering if maybe I could use the switch statement,
but I have to compare each colour to the string, and I can't do
that in a switch statement, can I?
Thanks for any help.
I hope this isn't off-topic.