[cc65] Re: cc65/C questions

From: Jonathan Graham Harston <jgh1arcade.demon.co.uk>
Date: 2006-09-14 00:10:57
>Message-ID: <20060909144856.GB28453@trixie.musoftware.de>
 
On Thu, Sep 07, 2006 at 10:00:17AM -0600, Tom Watt wrote:
> 1. Is there a function that will separate a string into an array of strings
> based on spaces?
 
If the string is in writable memory:
 
/* string is the string, eg "one two three",00 */
 
p=string;                  /* point to string start             */
n=0;                       /* 0th argument                      */
while (*p) {               /* while not pointing to terminator  */
  arg[n++]=p               /* point this arg[] to here          */
  while (*p > ' ') p++;    /* skip until space or ctrl char     */
  if (*p == ' ') {         /* if space, replace with terminator */
    *p=0;                  /* and step past to next string      */
    p++;
    }
  }
 
On input, if s=>"one two three",00.
On exit,  s=>"one",00,"two",00,"three",00 and
       arg[0]-^ arg[1]-^ arg[2]-^
       and n=2
 
so arg[0]=>"one",00 arg[1]="two",00 arg[2]="three",00
 
No range checking, can be improved, tramples on the source string,
multiple spaces give null string arguments, etc. etc. etc.
 
-- 
J.G.Harston - jgh@arcade.demon.co.uk - mdfs.net/User/JGH
Jet Set Willy Resources - http://mdfs.net/Software/JSW
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Thu Sep 14 01:00:32 2006

This archive was generated by hypermail 2.1.8 : 2006-09-14 01:00:36 CEST