H
H
hleb12022-02-17 17:04:30
Text Processing Automation
hleb1, 2022-02-17 17:04:30

How to effectively compare text?

I am writing a MUD game. I want to make controls using commands that the user enters (like bash in Linux, for example). To be more specific: the player enters the command use health_potion, the program processes the request (this is the question), then the program chooses to use the procedure usewith the parameter health_potion, and not close the game.
How should the program process the player's string in order to figure out which function to use?
Does she have to compare each character with the entire alphabet to decide what to do next?
Where to start digging? (resources) I tried to google, stumbled upon habr.

Ps Of course, I can use a bunch of if's, but...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
Wataru, 2022-02-17
@hleb1

You can create a table of actions with pointers to handler functions.

V
Vladimir Korotenko, 2022-02-17
@firedragon

In essence, you want to develop a state machine, there are tools for this
https://ru.wikipedia.org/wiki/Yacc
Use them

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question