Linux下的wfopen(手工打造)
2024-10-02 01:28:42
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[];
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 ;
}
http://intercontineo.com/article/840436823/
http://man7.org/linux/man-pages/man3/wcstombs.3.html
最新文章
- 1.Two Sum(c++)(附6ms O(n) accepted 思路和代码)
- 使用Gson转换json数据为Java对象的一个例子
- 如何为Eclipse安装主题(Color Theme)
- C# ~ NUnit单元测试
- js控制全屏窗口
- NGITOSS
- hdu 5310 Souvenir(BestCoder 1st Anniversary ($))
- 杭电ACM2097--Sky数
- spring mvc 错误
- MySQL数据库MyISAM和InnoDB存储引擎的比较(转)
- JavaScript电话号码正则
- nginx+php-fpm json_encode 到client pages 截断
- vue 父子组件传参
- foreach_and_函数
- C++雾中风景1:友元类与面向对象
- 软件配置管理及SVN的使用
- Mybatis框架基础支持层——反射工具箱之泛型解析工具TypeParameterResolver(4)
- Android冷启动优化
- Java构造器练习题
- 常见HTTP状态码及URL编码表