Solved

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

Posted on 2004-09-18
3
426 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
  • 2
3 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 250 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now