
Please Help: Reading & Writing from/to a Unicode File produces garbage in output file
On Wed, 19 Jul 2000 00:23:01 -0700, "Brad Williams"
Quote:
> I am attempting to write a program that reads from a UNICODE file and then
> writes out to a UNICODE file. The program reads from the UNICODE file, but
> the output file contains garbage.
> Any suggestions would be welcome.
> Thanks in advance.
> Brad
> // Header files
> #include <stdio.h>
> #define _UNICODE // define UNICODE support
I have no idea what this symbol means.
Quote:
> #include <tchar.h> // required for UNICODE support
This is not a standard header.
Quote:
> // main()
> void main()
The above is an illegal definition for main(). The C language
requires that main() be defined with a return type of int in a hosted
environment.
Quote:
> {
> // Declare local variables
> TCHAR tcTemp = _T('\0'); // temporary tchar
> FILE* fpSource = 0; // file pointer to source file
> FILE* fpDestination = 0; // file pointer to destination file
> // open the source file
> if (!(fpSource = _tfopen(_T("test.uni"), _T("r"))))
> {
> _tprintf(_T("Error: Could not open source file."));
> return;
> }
> // open the destination file... close out the source file pointer if error
> if (!(fpDestination = _tfopen(_T("myfile2.uni"), _T("w"))))
> {
> _tprintf(_T("Error: Could not open destination file."));
> fclose(fpSource);
> return;
> }
> // get a character from source file, and check for EOF
> while ((tcTemp = _fgettc(fpSource)) != _FEOF)
> {
> // if not EOF, copy it to the destination file
> _fputtc(tcTemp, fpDestination);
> }
> // be nice to your users
> _tprintf(_T("Success."));
> // if you open a pointer, close it.
> fclose(fpSource);
> fclose(fpDestination);
> }
You are asking in the wrong place. None of the following have
anything at all to do with the C language:
tchar.h
TCHAR
_T
_topen()
_tprintf()
Each and every one of these things is a compiler specific extension.
None of them are defined by or part of the C language, so there is
literally no C language answer to the question of how they should
work. Ask this in a support group for the particular compiler that
supplies these non-standard extensions.
Jack Klein
--
Home: http://jackklein.home.att.net
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://marshall-cline.home.att.net/cpp-faq-lite/
alt.comp.lang.learn.c-c++ http://www.faqs.org/faqs/C-faq/learn/