Re: strtok, bus error

Fundu <[email protected]>
Newsgroups org.kernel.vger.linux-c-programming
Message-ID <[email protected]>
Thanks Bryan and Ben. 
it makes sense now.


--- On Mon, 2/16/09, Bryan Christ <[email protected]> wrote:

> From: Bryan Christ <[email protected]>
> Subject: Re: strtok, bus error
> To: [email protected]
> Cc: [email protected]
> Date: Monday, February 16, 2009, 7:57 PM
> char src[]  = "hello world #"; is an automatic
> variable (char array)
> which is both read and write.
> char *other = "hello world #"; is a char * (which
> points to a string)
> of text allocated in the program's text (Data/BSS) area
> which is read
> only.
> 
> On Mon, Feb 16, 2009 at 8:52 PM, Fundu
> <[email protected]> wrote:
> > i'm trying to do pretty simple replacement using
> strtok.
> > but it looks like i have missed some subtle difference
> between the two following
> >
> >  char src[]  = "hello world #";
> >  char *other = "hello world #";
> >
> > because if i use "char * other" with strtok
> it fails with bus error but i use src it works, don't
> understand what's the difference.
> >
> > here's the code for strtok.
> >     char delims[] = "#";
> >     char *result = NULL;
> >     // this works
> >     result = strtok( src, delims );
> >     // this doesnot work and give a bus error
> >     // result = strtok(other, delims);
> >     while( result != NULL ) {
> >         printf( "result is
> \"%s\"\n", result );
> >         result = strtok( NULL, delims );
> >     }
> >
> > what am i missing here ? i thought both way of
> declaration(mentioned above ) were the same apparently the r
> not, whats the diff ?
> >
> > any insight would be appreciated, TIA!
> >
> >
> >
> > --
> > To unsubscribe from this list: send the line
> "unsubscribe linux-c-programming" in
> > the body of a message to [email protected]
> > More majordomo info at 
> http://vger.kernel.org/majordomo-info.html
> >
> 
> 
> 
> -- 
> Bryan
> <><
> --
> To unsubscribe from this list: send the line
> "unsubscribe linux-c-programming" in
> the body of a message to [email protected]
> More majordomo info at 
> http://vger.kernel.org/majordomo-info.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.