简体   繁体   中英

C++ Comparing files in 2 folders

I am generating hashes for the contents of two folders. I then want to compare all the hashes, one at a time of folder a to all the contents of folder b.

If they have equal files in each this works ok but I plan on having around 500 files in folder B and maybe 5-10 in folder A. the loop im using at the minute is as follows

for (i=0;i<nbfiles1;i++)
{
    printf("file1: %s\n", files1[i]);
    for (j=0;j<nbfiles2;j++)
    {
        printf("    file2: %s\n", files2[j]);
        cs=ph_audio_distance_ber(hashes[i],lens[i],hashes2[j],lens2[j],threshold,block_size,Nc);
        double max_f = 0.0;
        for (index=0;index<Nc;index++)
        {
            if (cs[index] > max_f)
                max_f = cs[index];
        }//end if
        printf("    cs = %f\n", max_f);
    }//end for
}//end for

where nbfiles1 is the number of files in folder A and nbfiles 2 is the number of files in folder B

The loop works fine if there are equal numbers of files in each but if there is an unequal number then it crashes. I know the answer is staring right at me but after 3 hours of looking it hasnt dawned on me where im going wrong.

A std::bad_alloc exception is raised when you don't have enouth memory, or try to allocate an invalid size. Check your code where memory allocations are done, and show us more if you don't find.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM