Re: skip_spaces()

From: Mark Devlin (markd@eskimo.com)
Date: 04/14/96


On Sun, 14 Apr 1996, JRhone wrote:

> for example: (if im reading this correctly and understanding it)
> say this is a char ptr argument passed to some function
> 
> "          hello, im an argument"
> 
> say str points to the beginning of that string

Assuming the above string is in "char buf[MAX_INPUT_LENGTH]", and
"char *str = buf", you'll only change where str points to by calling
skip_space(&str)
This has no effect on buf at all.

Now, if you had "char *str = malloc(MAX_INPUT_LENGTH)" and called 
skip_spaces(&str)
THEN you'd lose the bytes, since you're changing the only reference to
the memory.

> in some of the older code (im runnin base 2.2) i see a good way
> of skipping spaces like
> 
> for (i = 0; *(arg + i) == ' '; i++)
>   ;
> tmp = (arg + i);
> 
> you still have arg's original starting address this way...
> and tmp points to the meaty part of the string..

The skip_spaces() in 3.0 does that, except it'll also skip over anything
isspace() thinks is a space (space, tab, newline, carriage return, etc).
However, it leaves it up to 'you' to make and use pointers safely. Ie:
char *str = malloc(MAX_INPUT_LENGTH);
char *tmp = str;
skip_spaces(&tmp);

Hope that wasn't too confusing.  :-) 

- Mark
markd@eskimo.com	(finger markd@eskimo.com for my PGP signature)
http://www.eskimo.com/~markd	U.S.A. Home of the Alternate Reality page



This archive was generated by hypermail 2b30 : 12/18/00 PST