#include"stdafx.h"
#include<stdio.h>
#include <iostream>
#include <fstream>
using namespace std;
void main()
{
char s0[255];
char s1[255];
FILE *fp0 = NULL,*fp1 = NULL;
int i=0,j=0;
int Num=2;
sprintf(s0, "c:\\test0\\%d.txt", Num);
sprintf(s1, "c:\\test\\%d.txt", Num);
ifstream in(s1);
char str[1000];
int n=0;
while(!in.eof())
{
in.getline(str, sizeof(str)); //计算行数
n++;
}
int m0=n,m1=n;
int (*ary0)[3]=new int[m0][3];
int (*ary1)[3]=new int[m1][3];
char c='\n'; //定义换行转义字符
if((fp0=fopen(s0,"r"))!=NULL&&(fp1=fopen(s1,"r"))!=NULL)
{
for (i=0;i<n-1;i++)
{
for (j=0;j<3;j++)
{
fscanf(fp0,"%d",&ary0[i][j]); //转二维
fscanf(fp1,"%d",&ary1[i][j]);
if (ary0[i][0]==ary1[i][0]&&ary0[i][1]==ary1[i][1])
{
ary1[i][2]=ary1[i][2]-ary0[i][2];
}
}
}
fp1=fopen(s1,"w");
for (i=0;i<n-1;i++)
{
for (j=0;j<3;j++)
{
fprintf(fp1, "%d ", ary1[i][j]); //写入txt
}
fprintf(fp1,"%c",c);
}
fclose(fp0);
fclose(fp1);
fp0=NULL;
fp1=NULL;
}
delete[] ary0;
delete[] ary1;
return;
}
#include<stdio.h>
#include <iostream>
#include <fstream>
using namespace std;
void main()
{
char s0[255];
char s1[255];
FILE *fp0 = NULL,*fp1 = NULL;
int i=0,j=0;
int Num=2;
sprintf(s0, "c:\\test0\\%d.txt", Num);
sprintf(s1, "c:\\test\\%d.txt", Num);
ifstream in(s1);
char str[1000];
int n=0;
while(!in.eof())
{
in.getline(str, sizeof(str)); //计算行数
n++;
}
int m0=n,m1=n;
int (*ary0)[3]=new int[m0][3];
int (*ary1)[3]=new int[m1][3];
char c='\n'; //定义换行转义字符
if((fp0=fopen(s0,"r"))!=NULL&&(fp1=fopen(s1,"r"))!=NULL)
{
for (i=0;i<n-1;i++)
{
for (j=0;j<3;j++)
{
fscanf(fp0,"%d",&ary0[i][j]); //转二维
fscanf(fp1,"%d",&ary1[i][j]);
if (ary0[i][0]==ary1[i][0]&&ary0[i][1]==ary1[i][1])
{
ary1[i][2]=ary1[i][2]-ary0[i][2];
}
}
}
fp1=fopen(s1,"w");
for (i=0;i<n-1;i++)
{
for (j=0;j<3;j++)
{
fprintf(fp1, "%d ", ary1[i][j]); //写入txt
}
fprintf(fp1,"%c",c);
}
fclose(fp0);
fclose(fp1);
fp0=NULL;
fp1=NULL;
}
delete[] ary0;
delete[] ary1;
return;
}