Re: parsing string into an array



John Smith wrote:
> To store the output to a string array, I created a two-dimensional
> array and copied the output to the array:
>
> char output[5][55];
> (snip)
> This doesn't work. What's in the output array is nothing like the
> output (on screen). How should it be done?

Are you aware that this will fail if:
* there are more than 5 "tokens"
* one or more of the tokens is (are) longer than 54 characters

That said, there are a couple more things to know:
* strtok() alters the string it works on. So you can't use
it to parse the same string twice unless you have made a copy
of this string before. This may be what happens to you if
your program tries both of your parsing attempts one after
the other on the same string.
* strtok() is one of those "evilish" C std library functions,
because it maintains an internal structure and thus cannot be
used in nested calls. So you must use it with a lot of care,
and it really is safe only in the simplest programs (unless
you really know what you're doing).
Not worth it in my opinion, since it's so easy to implement
"by hand" in a safe manner.

As a side note, I will add that outside of textbooks, multidimensional
arrays in C are not particularly useful. Their syntax is often
misleading (in my opinion) and they can serve only very limited
purpose. I tend to prefer arrays of arrays, which are easier to handle
and more flexible (in my opinion).
.



Relevant Pages

  • Help in French|Spanish|German translation.
    ... I am also an author of User-defined string functions. ... WORDTRANEX (cSearched, cArExpressionSought | cExpressionSough, ... each string of the array is searched ... If the parameter nArStartOccurrence is -1 or omitted, the replacement starts ...
    (microsoft.public.fox.helpwanted)
  • Re: passing a string to a dll
    ... Joe, I really appreciate you taking the time to demonstrate this. ... sure how I would implement indexing it for random alphanumeric codes. ... I might handle the array. ... I actually have been wondering if I could use a second string ...
    (microsoft.public.vc.mfc)
  • Re: passing a string to a dll
    ... I might handle the array. ... I actually have been wondering if I could use a second string ... look at insertion cost, organization cost, and search cost. ...
    (microsoft.public.vc.mfc)
  • Re: Array Type Mismatch
    ... Dim resultAs String ... I am still somewhat confused as to why nothing is stored in the array. ... Public Function TextBoxGetLine(....arguments... ...
    (microsoft.public.access.formscoding)
  • Help in Spanish translation of the description of UDFs
    ... functions of minimum / maximum values among elements of an array column. ... GETALLWORDS- Inserts the words from a string into a global dimensioned ... WORDTRAN- Searches a character string for occurrences of a first word, ... ARRAYSUM- Returns the sum of all or a specified range of numeric (and/or ...
    (microsoft.public.fox.helpwanted)