Advertisement

Getting stuff from a string

Started by May 11, 2001 05:38 PM
1 comment, last by TheSalmon 23 years, 9 months ago
Hi. What''s a good way to get a command and its arguments from a string? Say the user enters a command and some args in a console or whatever, how should I go about extracting the individual parts of the resulting string in order to use them properly? Thanks in advance. --- No game will ever rule more than CBT!
---Mikael Lax
Well, you could parse the string and use something like a space to denote seperate args. WHat I mean by parse is go through the string looking for spaces, and seperate the args that way. THen you can match the command to a big command table that holds the command strings and their corresponding action, and you could use the args depending on what command they entered.
Advertisement
You can always use sscanf (stdio.h, ANSI C) or write your own string parsers (which are pretty easy to write, actually).

Resist Windows XP''s Invasive Production Activation Technology!
http://druidgames.cjb.net/

This topic is closed to new replies.

Advertisement