S
Susan Rice
I'm new to using CString. Why won't the following compile?
I'm using Microsoft Visual C++ 6.0
Line 37 which it complains about is the function:
37 CString ConvertFile(char *szFileName)
I tried throwing in a bunch of #includes but didn't help.
Here's the compiler errors:
Compiling...
UtoA.cpp
UtoA.cpp(37) : error C2146: syntax error :
missing ';' before identifier 'ConvertFile'
UtoA.cpp(37) : error C2501: 'CString' :
missing storage-class or type specifiers
UtoA.cpp(37) : fatal error C1004:
unexpected end of file found
Error executing cl.exe.
UtoA.exe - 3 error(s), 0 warning(s)
And here's the file UtoA.cpp I'm trying to compile:
(this code is from
http://www.codersource.net/win32_unicode_ascii.html)
#include "stdafx.h"
#include <cstring>
#include <windows.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
// http://www.codersource.net/win32_unicode_ascii.html
//Check if the file is UNICODE
int IsUnicodeFile(char* szFileName)
{
FILE *fpUnicode;
char l_szCharBuffer[80];
//Open the file
if((fpUnicode= fopen(szFileName,"r")) == NULL)
return 0; //Unable to open file
if(!feof(fpUnicode))
{
fread(l_szCharBuffer,80,1,fpUnicode);
fclose(fpUnicode);
if(IsTextUnicode(l_szCharBuffer,80,NULL))
{
return 2; //Text is Unicode
}
else
{
return 1; //Text is ASCII
}
}
return 0; // Some error happened
}
//Convert the file to ASCII type
CString ConvertFile(char *szFileName)
{
CString strTempFileName;
CString strInputFileName;
strInputFileName = szFileName;
char TempPathBuffer[260];
GetTempPath(260,TempPathBuffer);
FILE *fpASCII;
CStdioFileEx fpUnicode;
strTempFileName = TempPathBuffer;
strTempFileName += "TempUnicodecheck.txt";
if(IsUnicodeFile(szFileName) == 2)
{
//Open the UNICODE file
if(!fpUnicode.Open(szFileName,CFile::modeRead|CFile::typeBinary))
{
printf("Unable to open the unicode file\n");
return strInputFileName ;
}
//Create the temporary file
if((fpASCII = fopen(strTempFileName.operator
LPCTSTR(),"w+"))==NULL)
{
fpUnicode.Close();
printf("Unable to open the output file\n");
return strInputFileName;
}
CString strData;
while(fpUnicode.ReadString(strData))
{
strData += "\n";
fwrite(strData,sizeof(char),strData.GetLength(),fpASCII);
}
fflush(fpASCII);
fclose(fpASCII);
fpUnicode.Close();
return strTempFileName;
}
else
{
return strInputFileName;
}
}
int main(int argc, char* argv[])
{
printf("Hello World!\n");
return 0;
}
I'm using Microsoft Visual C++ 6.0
Line 37 which it complains about is the function:
37 CString ConvertFile(char *szFileName)
I tried throwing in a bunch of #includes but didn't help.
Here's the compiler errors:
Compiling...
UtoA.cpp
UtoA.cpp(37) : error C2146: syntax error :
missing ';' before identifier 'ConvertFile'
UtoA.cpp(37) : error C2501: 'CString' :
missing storage-class or type specifiers
UtoA.cpp(37) : fatal error C1004:
unexpected end of file found
Error executing cl.exe.
UtoA.exe - 3 error(s), 0 warning(s)
And here's the file UtoA.cpp I'm trying to compile:
(this code is from
http://www.codersource.net/win32_unicode_ascii.html)
#include "stdafx.h"
#include <cstring>
#include <windows.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
// http://www.codersource.net/win32_unicode_ascii.html
//Check if the file is UNICODE
int IsUnicodeFile(char* szFileName)
{
FILE *fpUnicode;
char l_szCharBuffer[80];
//Open the file
if((fpUnicode= fopen(szFileName,"r")) == NULL)
return 0; //Unable to open file
if(!feof(fpUnicode))
{
fread(l_szCharBuffer,80,1,fpUnicode);
fclose(fpUnicode);
if(IsTextUnicode(l_szCharBuffer,80,NULL))
{
return 2; //Text is Unicode
}
else
{
return 1; //Text is ASCII
}
}
return 0; // Some error happened
}
//Convert the file to ASCII type
CString ConvertFile(char *szFileName)
{
CString strTempFileName;
CString strInputFileName;
strInputFileName = szFileName;
char TempPathBuffer[260];
GetTempPath(260,TempPathBuffer);
FILE *fpASCII;
CStdioFileEx fpUnicode;
strTempFileName = TempPathBuffer;
strTempFileName += "TempUnicodecheck.txt";
if(IsUnicodeFile(szFileName) == 2)
{
//Open the UNICODE file
if(!fpUnicode.Open(szFileName,CFile::modeRead|CFile::typeBinary))
{
printf("Unable to open the unicode file\n");
return strInputFileName ;
}
//Create the temporary file
if((fpASCII = fopen(strTempFileName.operator
LPCTSTR(),"w+"))==NULL)
{
fpUnicode.Close();
printf("Unable to open the output file\n");
return strInputFileName;
}
CString strData;
while(fpUnicode.ReadString(strData))
{
strData += "\n";
fwrite(strData,sizeof(char),strData.GetLength(),fpASCII);
}
fflush(fpASCII);
fclose(fpASCII);
fpUnicode.Close();
return strTempFileName;
}
else
{
return strInputFileName;
}
}
int main(int argc, char* argv[])
{
printf("Hello World!\n");
return 0;
}