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;
    }
  • 相关阅读:
    vue 中input的输入限制
    PC端百度地理围栏、绘制工具以及判断当前坐标是否再围栏中
    js判断鼠标点击的是哪个键
    vue过滤器的使用
    3.Mybatis的配置解析
    2.MyBatis的CRUD操作
    4.JVM类加载器深入解析及重要特性剖析
    3.JVM的接口初始化规则与类加载器准备阶段和初始化阶段的重要意义分析
    2.JVM的类加载器
    1.JVM如何学习
  • 原文地址:https://www.cnblogs.com/SunWentao/p/1325687.html
Copyright © 2011-2022 走看看