Path: ...!news.nobody.at!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: vallor Newsgroups: comp.os.linux.advocacy Subject: Re: OT programming challenge: fastest/best/shortest C program to jumble a sentence, then restore it Date: Sat, 9 Mar 2024 03:31:26 -0000 (UTC) Organization: A noiseless patient Spider Lines: 35 Message-ID: References: <65e9cad3$0$4689$882e4bbb@reader.netnews.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Sat, 9 Mar 2024 03:31:26 -0000 (UTC) Injection-Info: dont-email.me; posting-host="ab4e216fb12235b831fdc816a1885311"; logging-data="1957547"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19du2s4MaFX+DgpjIA6g5Tk" User-Agent: Pan/0.155 (Kherson; c0bf34e gitlab.gnome.org/GNOME/pan.git; x86_64-pc-linux-gnu) Cancel-Lock: sha1:nIr943MUWNxzzlqerWIfgM2sk4Q= X-Face: \}2`P"_@pS86<'EM:'b.Ml}8IuMK"pV"?FReF$'c.S%u9 wrote in : > On Fri, 8 Mar 2024 15:41:13 -0500, DFS wrote: > >> Sorry. That's ALL from a crlf inserted by the newsreader. It compiled >> cleanly after I took it out. > > Yup... > > In production code I'd likely do > > char* sentence; > > sentence = strdup("Once you try it, you'll see it doesn't need spice."); > if (sentence == NULL) { > printf("strdup() failed: %s", strerror(errno)); > return -1; > } Seems like a lot of work that could be handled by char sentence[] = "initializer"; Am I missing something? > > Admittedly is the implied malloc() failed the odds of it printing > anything aren't great but might as well try. I probably would use > strtok_r() in production if there was a remote possibility that there > would be another nested strtok(). That's ruined more than one > programmer's day. > -- -v