From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: * X-Spam-Status: No, score=1.0 required=5.0 tests=BAYES_00,INVALID_MSGID, PP_MIME_FAKE_ASCII_TEXT,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 109fba,666fe02f45914704,start X-Google-Attributes: gid109fba,public X-Google-Thread: fc89c,666fe02f45914704,start X-Google-Attributes: gidfc89c,public X-Google-Thread: 1014db,666fe02f45914704,start X-Google-Attributes: gid1014db,public X-Google-Thread: 10db24,666fe02f45914704,start X-Google-Attributes: gid10db24,public X-Google-Thread: 103376,666fe02f45914704,start X-Google-Attributes: gid103376,public From: "Arkady V.Belousov" Subject: Re: What's the best language to learn? [was Re: Should I learn C Date: 1996/08/27 Message-ID: #1/1 X-Deja-AN: 176713278 distribution: su sender: usenet@msnews.munic.msk.su references: organization: Locus reply-to: ark@munic.msk.su newsgroups: comp.edu,comp.lang.ada,comp.lang.c,comp.lang.c++,comp.unix.programmer x-mailer: dMail [Demos Mail for DOS v2.04b] Date: 1996-08-27T00:00:00+00:00 List-Id: Hello! On 21-Aug-96 03:42 in <01bb8f12$6dbb5f00$32ee6fce@timhome2> Tim Behrendsen (tim@airshields.com) wrote: > Szu-Wen Huang wrote in article > <4vdnod$5i8@news1.mnsinc.com>... > > Mark Wooding (mdw@excessus.demon.co.uk) wrote: > > : char buf[...]; > > : char *p; > > : ... > > : while (buf[0]==' ') > > : { > > : for (p=buf;p[0]=p[1];p++) > > : ; > > : } > > : while (buf[strlen(buf)-1]==' ') > > : buf[strlen(buf)-1]=0 [] > > : Anyone who asks `what's wrong with that' will be shot. > > This code works, by the way, as far as I can tell. It's even portable. ^^^^^^^^^^^^^ > > I suggest you show us somebody with equivalent experience in general > > computing as this individual but started on assembly language and see how > > this person fares with the problem. Oh, and give them the same amount > > of time. > You're missing the point. The point is how can *anyone* commit such > a monument to inefficient coding? Yet, someone did. That someone > obviously sees four lines of code, and therefore it must be OK. > Now, if that someone had an assembly background, and could see how > these statements were going to compile, they would instantly feel > the horror that a good and moral programmer should feel over this > code. Yes! Your words are balm for me. ______________O\_/_________________________________\_/O______________ // strrnspn like strspn scan a string for a segment that is a subset of // a set of characters, but they reverse starting at specified position // This code tested and optimized size_t strrnspn(const char src[], const char sp[], size_t n){ size_t pos = n; while(pos--){ register char ch = src[pos]; for(const char *ss = sp; *ss && *ss != ch; ss++); if(*ss != ch) break; } return (n - pos - 1); } // Remove border segments, which contain only characters from specified set // This code not tested void trim(char s[], const char sp[] = " \t"){ size_t len = strlen(s); len -= strrnspn(s, sp, len); // Remove "right" (last) border size_t cut = strspn(s, sp); memmove(s[0], s[cut], len -= cut); // Remove "left" border s[len] = '\0'; // Terminate resulting string } _____________________________________________________________________ O/~\ /~\O This code something more complicated, but they also "even portable" and MUCH!!!! more efficient. (BTW. I think, first mentioned approach and codes are used in the Borland and Microsoft judging by they products). %~( P.S. Not much, but my (not showed there) trim function is more efficiency, because they manipulate on instance of String class, which know they length. * When we hear - Jump, we ask - How far? -- Best regards! Sincerely yours, ������ ���������. ����̣���� ���� �������� ��������, � ���������� ������ ����������.