Solved

how to tell if a file is unicode or ascii

Posted on 2001-06-07
2
680 Views
Last Modified: 2008-03-17
Hi,

I'm using Visual C++ 6.0 with Windows 2000.

I need to write a program that reads from a text file. The file will be encoded entirely in either ascii or unicode. I need to be able to read and interpret both.

How can determine which format is used (without using MFC)?

Thanks in advance,
m.
0
Comment
Question by:mikjimbob
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 150 total points
ID: 6165145
Load the file into memory and use the Win32 API 'IsTextUnicode()' (from the docs):

DWORD IsTextUnicode( CONST LPVOID lpBuffer,
// pointer to an input buffer to be examined

int cb,
// the size in bytes of the input buffer

LPINT lpi
// pointer to flags that condition text examination and receive results

);

The IsTextUnicode function determines whether a buffer probably contains a form of Unicode text. The
function uses various statistical and deterministic methods to make its determination, under the control
of flags passed via lpi. When the function returns, the results of such tests are reported via lpi.
If all specified tests are passed, the function returns TRUE; otherwise, it returns FALSE.

If you don't want to load the whole file, use a reasonable amount of bytes, which must be dividable
by 2.

Feel free to ask if you need more information!
0
 

Author Comment

by:mikjimbob
ID: 6167110
Perfect.

Cheers,
m.

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question