Re: Is it Unicode or Not ??
If it is just english strings within the text file, every odd character will be a null. However, if it is a real Unicode file all characters are potentially being used (and therefore it is going to be very difficult to tell).
Re: Is it Unicode or Not ??
I use this to determine if it is a textfile:
Returns in three ways (SUCCESS, FAILURE, IS_UNICODE)
Hope this helps
Mark
int is_text_file(LPSTR szFile)
{
FILE *stream;
int ch;
if (file_exists(szFile)!=SUCCESS)
{
return FAILURE;
}
int is_text = SUCCESS;
/* Open file to read */
if( (stream = fopen( szFile, "r" )) == NULL )
{
fclose( stream );
return FAILURE;
}
/* Read characters */
ch = fgetc( stream );
if (ch == 255)
{ //Unicode
while ((is_text==SUCCESS)&&( feof( stream ) == 0 ))
{
ch = fgetc( stream );
ch = fgetc( stream );
if ((ch < 9)&&(ch != EOF))
is_text = FAILURE;
}
if (is_text == SUCCESS)
{
is_text = IS_UNICODE;
}
}
else
{ //Ascii
while ((is_text==SUCCESS)&&( feof( stream ) == 0 ))
{
ch = fgetc( stream );
if ((ch < 9)&&(ch != EOF))
is_text = FAILURE;
}
}
fclose( stream );
return is_text;
}