Hello everyone, new programmer here.
I've been looking around recently for information that could help me with string comparisons. I haven't found anything so far and I am not sure the tutorial on the site was able to help me.
Right now I've been trying to make a short text-based game, and to perform actions in the game the player is to type such things as "pick up X" or "open Y" into the console. This is how I would like to it be ideally.
The obvious problem is that the user has to make an exact input (i.e. to "Read Book" the user has to type "Read Book" without error. I've tried playing around with the strcmp function but I can't seem to get it to work. I would like to not have to force this, but I don't want to default on a simple 1,2,3,etc. input system.
So I'm let with two options on making it accept multiple versions of the same input: make it so the comparison could be similar, or create a strcmp for each and every variable. The latter however seems horribly inefficient because it would mean making 2+ lines of code for every spelling. This leaves the former. And I've done stuff in the past where you could read "Examine Chest" as (examine|look.*at|see).+(chest|box), which would cover many variances in input. The problem is I have no idea if that is how it works when working with C, but it is my ideal solution.
Any help on this problem would be greatly appreciated!



1Likes
LinkBack URL
About LinkBacks



