in reply to C vs perl
This compiles under cygwin's gcc 2.95 in win98 and I'd be surprised if there were problems elsewhere (make sure you include string.h though!). I'm sure this could be golfed to heck with even more pointer trickery, but my point is that the as long as you are a competent craftsmen it doesn't really matter what tools you use.char* crlf2ptag(char* str) { char *ret, *pstr, *pret; /* ok, this could be done better but it's only a string ;-) */ ret = (char*) malloc(strlen(str) << 2 + 8); strncpy(ret, "<p>", 3); pstr = str; pret = &ret[3]; while(*pstr != '\0') if(*pstr == '\r' && *(pstr+1) != '\0' && *(pstr+1) == '\n') { strncpy(pret, "</p><p>", 7); pret += 7; pstr += 2; } else *pret++ = *pstr++; ret[strlen(ret) - 3] = '\0'; return ret; }
_________
broquaint
update: now checks for \r and \n to appease abstracts and should allocate enough space for all but the most \r\n ridden strings.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: C vs perl
by Dominus (Parson) on Apr 28, 2002 at 15:04 UTC | |
by broquaint (Abbot) on Apr 28, 2002 at 15:08 UTC | |
Re: Re: C vs perl
by meonkeys (Chaplain) on Apr 28, 2002 at 18:45 UTC | |
by Elian (Parson) on Apr 28, 2002 at 19:21 UTC | |
by h.toothrot (Initiate) on Apr 29, 2002 at 10:33 UTC | |
Re: Re: C vs perl
by abstracts (Hermit) on Apr 28, 2002 at 21:35 UTC | |
Re: Re: C vs perl
by czrdup (Acolyte) on Apr 29, 2002 at 17:42 UTC |