On Wed, 30 Jun 1999, Michael B Golden wrote:
> I was trying to work on a C program, but I can't figure out how
to do some
> things. What I am looking for is a command in C similar to the mid$
> command in Visual Basic. What I need to do is take a string out of
another
> string. I need to be able to specify the start point, and then end
point.
> I also need to find a function that can look through the string, and
find
> the first space (beginning where I tell it to, not the beginning), and
> return the value as an integer. Here is a sample line of input and what
I
> need it to output:
>
> Input: 0 Inbox FOLD0000.FRM 443 442 1 1
> Needed Output: Inbox
How do you expect it to give you "Inbox" as an integer? If you will
settle for a pointer to a string, since what you are really doing is
parsing a string into tokens, strtok (which is messy, non-reentrant and
generally deprecated, but is ANSII C and therefor portable) or strtok_r
or strsep. To move the strings into local variables, you could use
str[n]cpy. All of these seem to destroy the input data by substituting
\0 for each delimiter as it is found.
>
> Does anyone know how to do this? I tried using the strstr() function to
> find the space, but I couldn't figure out how to work with the pointer
it
> outputs.
char name[57];
char data[] = "0 Inbox FOLD0000.frm"
char *line = data;
foo = strsep(&line, " "); /* foo points to "0" */
foo = strsep(&line, " "); /* now foo points to "Inbox" */
strcpy(name, foo);
> And Lawson, do you know what the beginning 0 and the trailing 3 numbers
are? I
> know what the first one is.
Number of letters? Current letter number? Don't know. :-)
>
>
---------------------------------------------------------------------------------------------------------------------
> Michael Golden
> [EMAIL PROTECTED] (Normal, no attachments)
> [EMAIL PROTECTED] (Only for messages with attachments.)
> RedHat 5.2 (2.0.36) Linux user -- Linux Advocate
> ___________________________________________________________________ Get
the
> Internet just the way you want it. Free software, free e-mail, and free
> Internet access for a month! Try Juno Web:
> http://dl.www.juno.com/dynoget/tagj.
>
___________________________________________________________________
Get the Internet just the way you want it.
Free software, free e-mail, and free Internet access for a month!
Try Juno Web: http://dl.www.juno.com/dynoget/tagj.