samedi 22 décembre 2018

How do I check a string for a range of characters in C?

I have to create a Solitaire Program in C. I have the data structure set up but I have a question about comparing strings.

The user input has to look like "move [colour] [value] to [stack]".

Now my plan was to use strncmp to see if the string contained "move" "color", etc. But with "value" I have a range of 13 acceptable inputs (Ace to King), which means I would need 13 different if-statements. Is there a more elegant way to check which "value" the input holds?

Thanks!

Aucun commentaire:

Enregistrer un commentaire