?
Solved

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

Posted on 2004-09-18
3
Medium Priority
?
535 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops 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.
Suggested Courses

777 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