手记

通过C++实现逐格点运算

#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main()
{
    int a, b, s,cout=0;
    FILE *fin1, *fin2, *fout;
    fin1 = fopen("F:\\2017C\\test1.txt", "r");
    if ((fin1 = fopen("F:\\2017C\\test1.txt", "r")) == NULL)
    {
        printf("can not to open the file!\n");
        system("pause");
        exit(1);
    }
    fin2 = fopen("F:\\2017C\\test2.txt", "r");
    if ((fin2 = fopen("F:\\2017C\\test2.txt", "r")) == NULL)
    {
        printf("can not to open the file!\n");
        exit(1);
    }
    fout = fopen("F:\\2017C\\test.txt", "w");
    while (!feof(fin1) && !feof(fin2))
    {
        fscanf(fin1, "%d", &a);
        fscanf(fin2, "%d", &b);
        s = a + b;
        cout++;
        if (cout%4==0) fprintf(fout, "%d\n", s);
        else fprintf(fout, "%d\t", s);
    }

    fclose(fin1);
    fclose(fin2);
    fclose(fout);
    return 0;
}
12 23 45 56
32 65 45 58
65 54 123 123
//test1
1 1 1 1
2 2 2 2
3 3 3 3
//test2
13  24  46  57
34  67  47  60
68  57  126 126
//test
1人推荐
随时随地看视频
慕课网APP