所有dirent.h库函数似乎都未定义,包括DIR结构,但我包含了库。程序运行一秒钟然后崩溃,调试器在dirent.h代码中显示一个错误。还有解决我问题的另一种方法吗?我感到迷茫。
int main(int argc, char** argv)
{
int len;
struct dirent *pDirent;
DIR *pDir;
int i = 0;
FILE* virusSign = 0;
FILE* imageToScan = 0;
char* imageName = 0;
virusSign = fopen(argv[2], "r");
imageName = (char*)realloc(imageName, strlen(argv[1]) + 1);
strcpy(imageName, argv[1]);
DIR *dr = opendir(argv[1]);
pDir = opendir(argv[1]);
while ((pDirent = readdir(pDir)) != NULL)
{
imageName = (char*)realloc(imageName, strlen(argv[1]) + strlen(pDirent->d_name) + 2);
strcat(imageName, pDirent->d_name);
imageToScan = fopen(imageName, "r");
//printf("Choose option: \n1 - Normal scan. \n2 - Quick scan.");
normalScan(imageToScan, virusSign);
}