extern char * danCGIReplacedCRLF(char * szFixMe){ int i,j,iLen=0,iNewLen=0; int iCRLFcount=0; char* szResult=NULL; iLen=strlen(szFixMe); for (i=0;i<=iLen;i++){ if (szFixMe[i]==(int) '\n' || szFixMe[i]==(int) '\r') iCRLFcount++; } // need space for first

+NULL+ text // + replace each CR &LF + last " <\p>" iNewLen=3+1+strlen(szFixMe)+(iCRLFcount*8)+5; szResult = malloc(iNewLen); if (szResult){ szResult[0]='<'; szResult[1]='p'; szResult[2]='>'; szResult[3]='\0'; i=0; j=3; while (i<=iLen) if (szFixMe[i]==(int) '\n' || szFixMe[i]==(int) '\r'){ strcat(szResult,"

"); j+=8; // deal with Newline CR pairs if(szFixMe[i]==(int) '\n' && szFixMe[i+1]==(int) '\r' || szFixMe[i]==(int) '\r' || szFixMe[i+1]==(int) '\n') i+=2; else i++; }else{ szResult[j]=szFixMe[i]; j++; szResult[j]='\0'; //dest string in strcat needs terminating \0 i++; } //outer loop & if statement //end of new document needs

to match at start strcat(szResult,"

"); } // if(szResult !=NULL ) return szResult; }