比较两个文件的数字差异

#include <m_tools.h>
#include <stdio.h>
#include <assert.h>
#include <vector>
#include <string>
int main(int argc , char ** argv)
{

    assert( argc>=3 );
    FILE* file1, *file2;

    printf( "open file %s , %s ...\n", argv[1], argv[2] );

    file1 = fopen(argv[1],"r");
    file2 = fopen(argv[2], "r");

    if (!file1 || !file2) {
        printf("open files fail \n");
        getchar();
    }

    char str1[1024];
    char str2[1024];
    int linecount = 0;
    double d_max = 0;

    while (!feof(file1) && !feof(file2)) {
        ++linecount;
        fgets(str1, 1024, file1);
        fgets(str2, 1024, file2);  
        std::vector<float> nums1 = search_number_f( std::string( str1 ) );
        std::vector<float> nums2 = search_number_f(std::string(str2));

        int sz = __min(nums1.size(), nums2.size());
        for (int i = 0; i != sz; ++i) {
            double d = fabs(nums1[i]-nums2[i]);
            if (d > d_max) {
                printf( "find more different number %.8f, %.8f , diff=%.8f line=%d\n",nums1[i], nums2[i], d, linecount);
                d_max = d;
            }
        }
    }

    fclose(file1);
    fclose(file2);
    printf("done\n");
    getchar();
}

 

posted @ 2020-04-30 17:05  洛笔达  阅读(187)  评论(0编辑  收藏  举报