Re: possible memory leak?




Roman Mashak wrote:
> Thanks to all for replies.
>
>
> What's wrong with the code like this (code in original post gets dumped at
> *sp++ = '\0' statement, so I decided to simplify a little):
>
> char *s = "abcde"; /* s point to 'a' character */
> *s = 'A'; /* replace 'a' with 'A' */
> s++; /* move pointer to 'b' */
>

http://www.eskimo.com/~scs/C-faq/q1.32.html

You shouldn't modify string literals, such as
"abcde". Make a copy first, or do something like this:

char s[] = "abcde";

-David

.



Relevant Pages

  • Re: non-void function
    ... Thank you very much for replies, I got the point and fixed the code. ... With best regards, Roman Mashak. ... Prev by Date: ...
    (comp.lang.c)
  • Re: Why reply at the bottom of posts?
    ... > I'm just curious as to why so many replies are under the original post ... I tolerate either way, however, I think that it should be like the ... Prev by Date: ...
    (microsoft.public.windowsxp.general)
  • Re: Odd Error...
    ... but my original post on the subject was, let me see, late July. ... Couple weeks go by and I get no replies, I figured it was time to try ... some new newsgroups. ... Prev by Date: ...
    (comp.lang.basic.visual.misc)
  • Why reply at the bottom of posts?
    ... I'm just curious as to why so many replies are under the original post ... / ITinerant ... Prev by Date: ...
    (microsoft.public.windowsxp.general)
  • Re: big iron mainframe vs. x86 servers
    ... I asked because the pretty slide show linked to by the original post I ... replies, both explicit and implicit. ... The information contained in this communication (including any ...
    (bit.listserv.ibm-main)

Loading