zoukankan      html  css  js  c++  java
  • Linux下的wfopen(手工打造)

    Of Linux on wfopen (open wide-character version of the file name and mode) to achieve

    Not directly available on Linux wfopen function is used to open a wide-character file name, then we can convert a wide character char type, and then call the fopen function.

    #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!
    ");
        else
            printf("File open failed!
    ");
            
        /* int i;
        for(i = 0; i < SIZE; i++)
        {
            if(fread(&personArray[0], sizeof(struct person), i, pFile) != 1)
            {
                printf("File read failed at fread!
    ");
            }
        }
            
        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("
    ");*/
              
        /* use the second test case to test*/
        int c;
        while( (c = fgetc(pFile)) != EOF)
        {
            printf("%c", c);
        }
       fclose(pFile);
        
        return 0;
    }

    http://intercontineo.com/article/840436823/
    http://man7.org/linux/man-pages/man3/wcstombs.3.html

  • 相关阅读:
    bits,Bytes,KB,MB,GB和TB之间的换算关系
    idea快捷键
    拦截器Interceptor和过滤器Filter的区别
    JSTL标签
    EL 表达式
    El 表达式和 Jstl 标签库
    JavaWeb servlet,乱码的原因和解决
    java类从加载、连接到初始化过程
    js中获取监听键盘事件
    ASP.NET Core Web 支付功能接入 微信-扫码支付篇(转)
  • 原文地址:https://www.cnblogs.com/findumars/p/6404077.html
Copyright © 2011-2022 走看看