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, ������ ���������. ����̣���� ���� �������� ��������, � ���������� ������ ����������.