使用fwrite函数将文件保存到新目录的步骤如下:
FILE *sourceFile = fopen("path/to/source/file", "rb");
mkdir("path/to/destination/folder");
char destinationPath[256];
sprintf(destinationPath, "path/to/destination/folder/%s", "filename.ext");
FILE *destinationFile = fopen(destinationPath, "wb");
if (sourceFile && destinationFile) {
char buffer[1024];
size_t bytesRead;
while ((bytesRead = fread(buffer, 1, sizeof(buffer), sourceFile)) > 0) {
fwrite(buffer, 1, bytesRead, destinationFile);
}
}
fclose(sourceFile);
fclose(destinationFile);
这样,使用fwrite函数将文件保存到新目录的过程就完成了。
推荐的腾讯云相关产品:对象存储 COS(Cloud Object Storage)
领取专属 10元无门槛券
手把手带您无忧上云