formatline.c
/*
programmed by:
Josh Santomieri
Santomieri Systems
joshs@santsys.com

This function takes a line of text (tcLine), a buffer for the new line (tcNewLine) a find string (tcFind) and a replace string (tcReplace).
The tcNewline recieves a string with all of the tcFind replaced with tcReplace.
*/

int FormatLine(TCHAR *tcLine, TCHAR *tcNewLine, TCHAR *tcFind, TCHAR *tcReplace)
{
	int iLen, iFindLen, iReplaceLen;
	int i = 0, j = 0, k = 0, l = 0;

	iLen = (int)strlen(tcLine);
	iFindLen = (int)strlen(tcFind);
	iReplaceLen = (int)strlen(tcReplace);
    
	if(iLen <= 0 || iFindLen <= 0 || iReplaceLen <= 0)
		return 0;

	if(strstr(tcLine, tcFind) == NULL)
		return 1;

	if(iFindLen == 1)
	{

		while(i < iLen)
		{
			if(*(tcLine+i) == *(tcFind))
			{
				strcat(tcNewLine, tcReplace);
				k += iReplaceLen - 1;
			}
			else
				*(tcNewLine+k) = *(tcLine+i);

			i++;
			k++;
		}
	}
	else
	{
		j = 0;
		i = 0;
		k = 0;
		while(i < iLen)
		{
			if(*(tcLine+i) == *(tcFind+j))
			{ 
				l = i;
				while(*(tcLine+l) == *(tcFind+j))
				{
					j++;
					l++;
				}
				if(j == iFindLen)
				{
					strcat(tcNewLine, tcReplace);
					k += (iReplaceLen);
					i += iFindLen; 
				}
				else
				{
					*(tcNewLine+k) = *(tcLine+i);
					k++;
					i++;
				}

				j = 0;
			}
			else
			{
				*(tcNewLine+k) = *(tcLine+i);
				k++;
				i++;
			}
		}
	}

	return 1;
}