Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Correct way of doing string manipulation functions Date: Tue, 10 Jan 2017 19:19:05 -0800 Organization: None to speak of Lines: 23 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="773e6a95afbb07ee2983b9f78b62bfd0"; logging-data="1270"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+l2jAFslJUpXd6xSvzZp2t" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:ygbSh7Zk9tUfIJQ8RnBTVYf9YRQ= sha1:/MhaqDvJOfDEGujXUQ+Z8SBJ0O4= Xref: csiph.com comp.lang.c:101420 ram@zedat.fu-berlin.de (Stefan Ram) writes: > "Fernando D. Bozzo" writes: [...] >> char *text_out = malloc(sizeof(text_in)); > > malloc might return 0. To be clear in case the OP isn't aware, if malloc() fails it returns a null pointer. A null pointer constant can be represented in source either as 0 or as NULL. > And sizeof(text_in) is a compile-time constant. > This might not be what you had in mind. More to the point, text_in is a pointer, so sizeof(text_in) almost certainly isn't what you want. [...] -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"