I'm trying to make an HTML tag converter.. it will accept a file name, and convert all HTML tags within it to the specified uppercase or lowercase. However, I need to convert some CStrings to chars to be used as the filename. This is what I have so far, but it's crashing when I run it, and debug points to my conversion.
Code:
void CHTMLConvertDlg::OnConvert()
{
UpdateData(TRUE);
m_sFileName.Replace('\\','/');
m_sFileNameOut.Replace('\\','/');
ifstream fin;
ofstream fout;
char *fileNameIn = new char[m_sFileName.GetLength()];
char *fileNameOut = new char[m_sFileNameOut.GetLength()];
for (int i = 0; i < m_sFileName.GetLength(); i++)
{
fileNameIn[i] = m_sFileName.GetAt(i);
}
for (i = 0; i < m_sFileNameOut.GetLength(); i++)
{
fileNameOut[i] = m_sFileName.GetAt(i);
}
fin.open(fileNameIn, ios::nocreate);
fout.open(fileNameOut);
delete[] fileNameIn;
delete[] fileNameOut;
if (!fin.fail())
{
while (!fin.eof())
{
BeginWaitCursor();
char line[255];
fin.getline(line, 255, '\n');
//fin.close();
CString string = line;
int firstOffset = 0;
int secondOffset = 0;
if (!string.IsEmpty())
{
while (firstOffset != -1)
{
int firstOffset = string.Find('<', firstOffset);
int secondOffset = string.Find('>', firstOffset);
CString smallString;
for (int i = 0; i < (secondOffset - firstOffset); i++)
{
smallString =+ string.GetAt(firstOffset + 1);
}
if (m_bCase)
{
smallString.MakeUpper();
} else {
smallString.MakeLower();
}
for (i = 0; i < (secondOffset - firstOffset); i++)
{
char temp;
temp = smallString.GetAt(i);
string.SetAt(firstOffset + 1 + i, temp);
}
}
if (firstOffset == -1)
{
char *tempString = new char[string.GetLength()];
for (i = 0; i < string.GetLength(); i++)
{
tempString[i] = string.GetAt(i);
}
fout.write(tempString, string.GetLength());
delete[] tempString;
}
}
}
if (fin.eof())
{
EndWaitCursor();
AfxMessageBox("Finished");
}
}
}
How can I convert CString to char?