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++){ /* this should be i < len */ if (szFixMe[i]==(int) '\n' || szFixMe[i]==(int) '\r') iCRLFcount++; /* and here you're counting how many \r or \n you see, not how many "\r\n" sequences */ } /* you don't need the

+NULL+text, you need

+text */ // 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){ /* what's wrong with strcpy(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'){ /* here again, you're checking for \r or \n, now the pair */ strcat(szResult,"

"); j+=8; /* and now I'm completely lost!, why are you looking for \n\r? I thought we were looking for \r\n. */ // 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 termin +ating \0 i++; } //outer loop & if statement //end of new document needs

to match at start strcat(szResult,"

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