zoukankan      html  css  js  c++  java
  • C 读文件

    1.纯c读文件

    int Utf2char(char *src, char** ret)
    {
    	int nret;
    	WCHAR   *pwchar = 0;
    	int codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
    	nret = MultiByteToWideChar(CP_UTF8, 0, src, -1, NULL, 0);
    	pwchar = (WCHAR *)malloc(sizeof(WCHAR)*nret);
    	nret = MultiByteToWideChar(CP_UTF8, 0, src, -1, pwchar, nret);
    
    	nret = WideCharToMultiByte(codepage, 0, pwchar, -1, 0, 0, 0, 0);
    	*ret = (char*)malloc(nret + 1);
    	nret = WideCharToMultiByte(codepage, 0, pwchar, -1, *ret, nret, 0, 0);
    	free(pwchar);
    	return nret;
    
    }
    

      

        
    FILE *pFile = NULL;
    	pFile = fopen("D:\codeOneSelf\****\Debug\34.txt", "rb+");
    	if (!pFile) {
    		return -1;
    	}
    
    	fseek(pFile, 0, SEEK_END);
    	int len = ftell(pFile);
    	fseek(pFile, 0, SEEK_SET);
    	char *buf = NULL;
    	buf = (char *)malloc(len + 1);
    	memset(buf, 0x00, len + 1);
    
    	fread(buf, len, 1, pFile);
    	fclose(pFile);
    	char *gb2312 = NULL;
    	gb2312 = (char *)malloc(BUFFER_LEN * 20);
    	memset(gb2312, 0x00, BUFFER_LEN * 20);
    	Utf2char(buf, &gb2312);
       free(buf);
       free(gb2312);
    

      

  • 相关阅读:
    python
    python
    python
    Django学习手册
    python
    Django学习手册
    [ThinkPHP] 独立分组配置,坑!!!
    vim 代码片段:通过vundle插件管理器安装ultisnips |centos6.5|vim7.2
    CESHI
    thinkphp实现功能:验证码
  • 原文地址:https://www.cnblogs.com/alinh/p/11251899.html
Copyright © 2011-2022 走看看