回复 9楼 TonyDeng
那版主可否帮小妹编写一个程序。把桌面一个文件a里的内容以二进制(0-1)代码的形式输出发到桌面的文件b~文件a和文件b都是已经建好的哦~

既然还有不甘心
就还没到放弃的时候~
程序代码:
#include <stdio.h>
#include <stdlib.h>
#define __VC__
/*
功能:複製文件
參數:targetFilename -- 目標文件名,可帶絕對或相對路徑
sourceFilename -- 源文件名,可帶絕對或相對路徑
返回:如果操作成功,返回零,否則返回系統錯誤碼(非零),查閱此錯誤碼信息包含致錯原因
*/
int Copy_File(const char* targetFilename, const char* sourceFilename)
{
FILE* source; // 源文件句柄
FILE* target; // 目標文件句柄
errno_t errorCode = 0; // 錯誤碼
int ch; // 文件讀寫的單個字節
#ifdef __VC__
errorCode = fopen_s(&source, sourceFilename, "rb"); // 以二進制讀模式打開源文件
if (errorCode != 0)
{
return errorCode;
}
#else
source = fopen(sourceFilename, "rb");
if (source == NULL)
{
return !0;
}
#endif
#ifdef __VC__
errorCode = fopen_s(&target, targetFilename, "wb"); // 以二進制寫模式創建目標文件
if (errorCode != 0)
{
fclose(source);
return errorCode;
}
#else
target = fopen(targetFilename, "wb");
if (target == NULL)
{
fclose(source);
return !0;
}
#endif
// 複製
for (ch = fgetc(source); ch != EOF; ch = fgetc(source))
{
fputc(ch, target);
}
fclose(target); // 關閉目標文件,系統刷寫數據流至磁盤文件
fclose(source); // 關閉源文件
return errorCode;
}
int main(int argc, char* argv[])
{
Copy_File("D:\\test_new.prg", "D:\\test.prg");
return EXIT_SUCCESS;
}




程序代码:
#include <stdio.h>
#include <stdlib.h>
#define __VC__
/*
功能:複製文件
參數:sourceFilename -- 源文件名,可帶絕對或相對路徑
targetFilename -- 目標文件名,可帶絕對或相對路徑
返回:如果操作成功,返回零,否則返回系統錯誤碼(非零),查閱此錯誤碼信息包含致錯原因
*/
int Copy_File(const char* sourceFilename, const char* targetFilename)
{
FILE* source; // 源文件句柄
FILE* target; // 目標文件句柄
errno_t errorCode = 0; // 錯誤碼
int ch; // 文件讀寫的單個字節
#ifdef __VC__
errorCode = fopen_s(&source, sourceFilename, "rb"); // 以二進制讀模式打開源文件
if (errorCode != 0)
{
return errorCode;
}
#else
source = fopen(sourceFilename, "rb");
if (source == NULL)
{
return !0;
}
#endif
#ifdef __VC__
errorCode = fopen_s(&target, targetFilename, "wb"); // 以二進制寫模式創建目標文件
if (errorCode != 0)
{
fclose(source);
return errorCode;
}
#else
target = fopen(targetFilename, "wb");
if (target == NULL)
{
fclose(source);
return !0;
}
#endif
// 複製
for (ch = fgetc(source); ch != EOF; ch = fgetc(source))
{
fputc(ch, target);
}
fclose(target); // 關閉目標文件,系統刷寫數據流至磁盤文件
fclose(source); // 關閉源文件
return errorCode;
}
/*
功能:使用命令行參數,將第一個文件複製為第二個文件
*/
int main(int argc, char* argv[])
{
const char* sourceFilename;
const char* targetFilename;
if (argc >= 3)
{
sourceFilename = argv[1];
targetFilename = argv[2];
Copy_File(sourceFilename, targetFilename);
}
return EXIT_SUCCESS;
}
