Sujet : Re: OT programming challenge: fastest/best/shortest C program to jumble a sentence, then restore it
De : vallor (at) *nospam* cultnix.org (vallor)
Groupes : comp.os.linux.advocacyDate : 09. Mar 2024, 05:31:26
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <usgl6d$1rnlb$3@dont-email.me>
References : 1 2 3 4 5 6 7
User-Agent : Pan/0.155 (Kherson; c0bf34e gitlab.gnome.org/GNOME/pan.git; x86_64-pc-linux-gnu)
On 9 Mar 2024 03:14:10 GMT, rbowman <
bowman@montana.com> wrote in
<
l522g2FqgibU6@mid.individual.net>:
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