zoukankan      html  css  js  c++  java
  • Linux和OS X上的wfopen,打开宽字符版的文件名和模式(filename, mode)

    Linux和OS X上的wfopen,打开宽字符版的文件名和模式(filename, mode)

                                                                                                   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, %d, %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;
    }
  • 相关阅读:
    洛谷P2664 树上游戏(点分治)
    洛谷P3366 【模板】最小生成树(Boruvka算法)
    loj#2312. 「HAOI2017」八纵八横(线性基 线段树分治)
    noi.ac#309 Mas的童年(子集乱搞)
    loj#6041. 「雅礼集训 2017 Day7」事情的相似度(SAM set启发式合并 二维数点)
    Windows phone应用开发[22]-再谈下拉刷新
    Windows phone应用开发[21]-图片性能优化
    Windows phone应用开发[20]-禁止Pivot手势
    Windows phone应用开发[19]-RSA数据加密
    Windows phone应用开发[18]-下拉刷新
  • 原文地址:https://www.cnblogs.com/SunWentao/p/1325687.html
Copyright © 2011-2022 走看看