不同目录中的文件比较 [英] File comparison in different directories

查看:161
本文介绍了不同目录中的文件比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,用于将一个目录中的文件与另一个目录中的文件进行比较.我在代码中没有错误和警告.当我尝试执行时,它停止工作并在代码块软件(我用来执行代码)中显示错误进程终止,状态为-1073741510(0分钟8秒).有人可以调试代码吗? (包含stdio,stdlib,dirent.h头文件)

#include< stdio.h>
#include< stdlib.h>
#include< dirent.h>
int main(int argc,char * argv []){
char * dir1 [100],* dir2 [100],行[100],行1 [100];
DIR * d;
int match = 1;
文件* f1,* f2,* c;
struct dirent * dir;
d = opendir("match1");
int i,j,k1 = 0,k2 = 0;
如果(d)
{
while((dir = readdir(d))!= NULL)
{
dir1 [k1 ++] =(dir->; d_name);
}
}
d = opendir("match2");
如果(d)
{
while((dir = readdir(d))!= NULL)
{
dir2 [k2 ++] =(dir->; d_name);
}
}
for(i = 0; i< = k1; i ++)
{
for(j = 0; j< = k2; j ++)
{
match = 1;
f1 = fopen("dir1 [i]","r");
f2 = fopen("dir2 [j]","r");
while((!feof(f1))&&(!feof(f2)))
{
if((fgets(line,1,f1))!=(fgets(line1,1,f2)))
match = 0;
休息;
}
if(match = 1&&feof(f1)&& feof(f2))
{
c = fopen("result.txt","w");
fprintf(c,dir1 [i],",dir2 [j],"\ n");
}
fclose(f1);
fclose(f2);
}
}
}

谢谢,
Sja

解决方案

写道:​​

有人可以调试代码吗?



是的你可以.这是一个有关如何调试它的想法.创建一个将一些文本写入文件的函数.在上面的代码中添加一串调用此函数的行.每行可以传入不同的字符串(检查点1",检查点2",检查点3"等).这样,当它失败时,您将知道它在哪里失败.确保每次写入时都将输出刷新到文件中...否则,某些文本可能会被缓存,并且您将不知道程序真正在哪里出了问题.


Hi, I have the following code for comparing files in one directory against files in another directory. I have no errors and warnings in the code. When I try to execute it stops working and shows the error Process terminated with status -1073741510 (0 minutes, 8 seconds)in the code blocks software( which I use to execute the code).Can anyone debug the code? (have included stdio,stdlib,dirent.h header files)

#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
int main(int argc, char *argv[]) {
char *dir1[100], *dir2[100],line[100],line1[100];
DIR *d;
int match=1;
FILE *f1,*f2,*c;
struct dirent *dir;
d = opendir("match1");
int i,j,k1=0,k2=0;
if (d)
{
while ((dir = readdir(d)) != NULL)
{
dir1[k1++]=(dir->;d_name);
}
}
d = opendir("match2");
if (d)
{
while ((dir = readdir(d)) != NULL)
{
dir2[k2++]=(dir->;d_name);
}
}
for(i=0;i<=k1;i++)
{
for(j=0;j<=k2;j++)
{
match=1;
f1=fopen("dir1[i]","r");
f2=fopen("dir2[j]","r");
while((!feof(f1)) && (!feof(f2)))
{
if((fgets(line,1,f1))!= (fgets(line1,1,f2)))
match=0;
break;
}
if (match = 1 && feof(f1) && feof(f2))
{
c=fopen("result.txt","w");
fprintf(c,dir1[i],"", dir2[j],"\n");
}
fclose(f1);
fclose(f2);
}
}
}

Thanks,
Sja

解决方案

wrote:

Can anyone debug the code?



Yes, you can. Here is an idea for how you might debug this. Create a function that writes some text to a file. Add a bunch of lines in your above code that call this function. Each line could pass in a different string ("Checkpoint 1", "Checkpoint 2", "Checkpoint 3", etc.). That way, when it fails, you''ll have an idea of where it fails. Make sure to flush the output to the file each time you make a write... otherwise, some of the text may get cached and you will not know where your program really had the problem.


这篇关于不同目录中的文件比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆