cを使用して、Windowsディレクトリの内容をファイルに書き込もうとしています。たとえば、jpeg のディレクトリ (つまり、複数の jpeg を含むディレクトリ) があり、それらを .raw ファイルに変換したい場合、次のようなものがあります。
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
typedef uint8_t BYTE;
#define BLOCK 512*sizeof(BYTE);
int main(void)
{
FILE * fd = fopen("C:\\jpegs", "r");
if (fd == NULL) {
fprintf(stderr, "Error opening device file.\n");
return EXIT_FAILURE;
}
int block = BLOCK;
FILE * fn = fopen("new.raw", "w+");
void * buff = malloc(block);
while(feof(fd) == 0) {
fread(buff,block,1,fd);
fwrite(buff,block,1,fn);
}
free(buff);
fclose(fd);
fclose(fn);
return 0;
}
問題は、Windows ディレクトリが EOF で終了しているとは思わないことです。これを解決する方法について誰かアイデアがありますか?