TIP: Click on subject to list as thread! ANSI
echo: rberrypi
to: AHEM A RIVET`S SHOT
from: KEITH THOMPSON
date: 2019-02-25 13:36:00
subject: Re: C is not a low level

Ahem A Rivet's Shot  writes:
[...]
>  For a more dramatic example of efficiency consider strtok(), the
> routine at the heart of turning a string into argc and argv. It works by
> injecting nulls into the string where the spaces are and returning an array
> of pointers to the starts of the words in the original string - In other
> words it turns a single string into several strings and returns them in an
> array - and it does so in place without using more memory than is
> absolutely essential. Doing string manipulation in place with minimal
> overhead was very important at the time C was designed.

Quibble: No, strtok() doesn't return an array of pointers (for the
simple reason that a C function cannot return an array value).  It
returns a single string pointer on each call.  You have to call it
multiple times to get pointers to all the tokens.  It uses its own
static memory to keep track.

Incidentally, I don't believe strtok is used to turn a string into argc
and argv.  That's handled by the shell, and tokenizing on white space
doesn't work.  For example:

    echo arg1 'arg 2'

passes two arguments to echo, not three.  (bash does use strtok in some
places; I'm not sure just how it's used.)

[followups to comp.lang.c]

--
Keith Thompson (The_Other_Keith) kst-u@mib.org  
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)

SOURCE: echomail via QWK@docsplace.org

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.