c写文件

来源:互联网 发布:企业网站cms 编辑:程序博客网 时间:2024/05/21 14:52


void WritHexFile( char* szPath, char* pBuf, int nLen ){if (pBuf == NULL || nLen < 1){return;}try{FILE* file;file = fopen(szPath, "ab+");fwrite(pBuf, 1, nLen, file);fwrite("\n", 1, 1, file);fclose(file);}catch (exception* e){printf("file error!\n",e);}}void ReadHexFile(char* szPath, char* pBuf, int nLen){if (pBuf == NULL || nLen < 1){return;}try{FILE* file;file = fopen(szPath, "ab+");if (NULL == file){printf("failed to open dos.txt\n");return;}char szTest[1024] = { 0 };while (!feof(file)){memset(szTest, 0, sizeof(szTest));fgets(szTest, sizeof(szTest) - 1, file); // 包含了\n  printf("%s", szTest);}fclose(file);}catch (exception* e){printf("file error!\n", e);}}


原创粉丝点击