For wfopen on Linux and OS X, open the file name and mode (filename, mode) of the wide character version)

Source: Internet
Author: User
For wfopen on Linux and OS X, open the file name and mode (filename, mode) of the wide character version)

Wentao sun.

# Include <stdio. h>
# Include <wchar. h>
# Include <stdlib. h>

# Define max_path 1024

File * wfopen (const wchar_t * filename, const wchar_t * Mode)
{
Char FN [max_path];
Char M [max_path];
Wcstombs (FN, filename, max_path );
Wcstombs (M, mode, max_path );
Return fopen (FN, M );
}

# Define size 4

Struct person
{
Char name [10];
Int year;
Int month;
Int Day;
} Personarray [size];

Int main ()
{
Wchar_t * filename = l "/perforce/sandbox/1.txt ";
Wchar_t * mode = l "R ";

File * pfile = wfopen (filename, mode );
If (pfile)
Printf ("file open successeed! \ N ");
Else
Printf ("file open failed! \ N ");

/* Int I;
For (I = 0; I <size; I ++)
{
If (fread (& personarray [0], sizeof (struct person), I, pfile )! = 1)
{
Printf ("File Read failed at fread! \ N ");
}
}

Fclose (pfile );


For (I = 0; I <size; I ++)
{
Printf ("% s, % d", personarray [I]. Name, personarray [I]. Year, personarray [I]. Month,
Personarray [I]. Day );
Printf ("");
}

Printf ("\ n ");*/

/* Use the second test case to test */
Int C;
While (C = fgetc (pfile ))! = EOF)
{
Printf ("% C", C );
}
Fclose (pfile );

Return 0;
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.