Re: I'm sorry...



Good point...BUT, this dies too:

#include <stdio.h>
#include <string.h>

void main() {
    char* var = "hey you";

    printf ("%s\n", strtok (var, " "));
}

shane

On Tue, 1 Dec 1998, Tomas Ogren wrote:

> 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
> 
> 
> -- 
>         FAQ: Frequently-Asked Questions at http://www.gnome.org/gnomefaq
>          To unsubscribe: mail gnome-list-request@gnome.org with 
>                        "unsubscribe" as the Subject.
> 
> 



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