#### Archived

This topic is now archived and is closed to further replies.

# sscanf(?)

This topic is 6417 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I decided to make a simple little scripting engine in c, and i''ve run into a little problem. i havent started to program it yet, because i want to make sure i know what i''m doing first ... anyway, so far (although its only on paper) it has the capability to read in a command from a ''script'' file, and put it (and it''s paremeters) into a string variable. Now i want it to figure out which command i want to run, and run it using it''s paremeters... i looked through a book of mine, and the command i thought might work the best is sscanf. my question is, will this work:
  if (sscanf(command_to_run,"move %s %i %i",playername,xmove,ymove)){ move(playername,xmove,ymove); } //just for fun, another one... (hey that rhymes) if (sscanf(command_to_run,"load_map %s",loadthismap)){ loadmap(loadthismap); } 
assuming command_to_run = "move player1 3 4", i guess this example would move the player named ''player1'' 3 to the right and 4 to the left. It doesnt matter though, i just want to know if this will work,or theres an easier way...

##### Share on other sites
You should do it like this (if I understand what you want):
  /* Declare you variables here *//* Get stuff in command_to_run now... */char command_value[50];sscanf(command_to_run,"%s",command_value);if(strcmp(command_value,"move") { /* %*s means discard the first string */ sscanf(command_to_run,"%*s%s%i%i",playername,&xmove,&ymove); move(playername,xmove,ymove);} else if(strcmp(command_value,"load_map") { sscanf(command_to_run,"%*s%s",loadthismap) loadmap(loadthismap); } else { /* ... */}

"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said

http://www.gdarchive.net/druidgames/

1. 1
2. 2
3. 3
Rutin
17
4. 4
5. 5

• 14
• 9
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
632912
• Total Posts
3009185
• ### Who's Online (See full list)

There are no registered users currently online

×