Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Tokenizing a string (since strtok() appears to be deprecated)

Posted on 2004-09-18
3
Medium Priority
?
552 Views
Last Modified: 2008-02-01
Okay, first off, this question *is* related to a homework assignment, however it's not the main thrust of it -- the assignment is to write a rudimentary analogue of gdb for a toy VM for an operating systems course.   That being said, if anyone doesn't want to answer on the basis of the preceding, feel free.

Anyway, as part of the debugger, I'm needing to parse commands entered by the user.  What I need is to take a string and get two things out of it.. essentially argc and argv[].  So, since every manpage on the subject says "Don't use strtok!!!" what are the alternatives, and how should I go about getting all of this info?  The text is going to be a series of integer values separated by spaces.  Anything else should allow me to spit out an error.

I just want to reiterate that this is *not* the assignment, this is a small part of it, and the rest is the hard part -- which I'm doing myself.  Please don't chew me out over this :)
0
Comment
Question by:offline314159
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 750 total points
ID: 12093924
If you have to parse a string that contains many integers separated by spaces, then sscanf() appears to be enough.
Even if you have different arguments for different command, then you can analize command first and the do sscanf() according to command syntax.
0
 

Author Comment

by:offline314159
ID: 12094082
Sounds promising...

However, there's the potential of arbitrary numbers of arguments.  Is there a graceful way of handling this?  I suppose there's always an array of int* that I can fill as I go, keeping count...

I would prefer an easier method, though :)
0
 

Author Comment

by:offline314159
ID: 12094170
Oh well. I'm just limiting the number of arguments to something manageable, and I'll hope that it's good enough.  What are the odds that they're going to throw more than 10 addresses at a set breakpoint instruction anyway ?  (famous last words, I know...)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question