Re: I'm sorry...



On 30 November, 1998 - sml13@cornell.edu sent me these 0.9K bytes:

> ...to abuse the list like this (this will be the only time, I promise), 
> but can any of you GCC/C hackers out there tell me why Gcc (2.7.2.3 on 
> Linux x86) segfaults on execution of this program:
> 
> #include <stdio.h>
> #include <string.h>
> 
> void main() {
>     printf ("%s\n", strtok ("hey you", " "));
> }
> 
> This is a correct usage of strtok, from what I have read.

man strtok:
"The functions strcat(), strncat(), strcpy(), strncpy(), strtok(), and
strtok_r() all alter their first argument."

Is it good to modify a constant string?

/Tomas
-- 
Tomas Ögren, stric@ing.umu.se, http://www.ing.umu.se/~stric/
|- Student of Computer Science at the University of Umeå
`- Sysadmin at {ing,acc}.umu.se



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]