linux下宽字符文件, Linux上 wfopen(打开宽字符版的文件名和模式)的实现 (**)

176 篇文章 13 订阅
118 篇文章 11 订阅

目录

linux下宽字符文件,Linux上wfopen(打开宽字符版的文件名和模式)的实现

-------------------------------------------------------

https://blog.csdn.net/ken2232/article/details/130316198
QString::toWCharArray 与 宽字符路径、空格 (测试OK)(***)

===================================

linux下宽字符文件,Linux上wfopen(打开宽字符版的文件名和模式)的实现

#include #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;
}

  https://blog.csdn.net/weixin_29214715/article/details/116863931

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值