#include <stdio.h>
#include <stdlib.h>
#define MAX_SIZE 1024
int main()
{
FILE *fp1;
FILE *fp2;
FILE *fp3;
char s1[MAX_SIZE];
char s2[MAX_SIZE];
char s3[MAX_SIZE];
char *ptr1 = s1;
char *ptr2 = s2;
char *ptr3 = s3;
int sum[MAX_SIZE];
int i;
if((fp1 = fopen("text1.txt", "r+")) == NULL)
{
printf("open text1.h error!\n");
}
if((fp2 = fopen("text2.txt", "r+")) == NULL)
{
printf("open text2.h error!\n");
}
if((fp3 = fopen("text3.txt", "w+")) == NULL)
{
printf("open text3.txt error!\n");
}
fgets(ptr1, 6, fp1);
fgets(ptr2, 6, fp2);
for(i = 0; i < 9; i++)
{
fseek(fp1, 1L, 1);
fseek(fp2, 1L, 1);
ptr1 = fgets(ptr1, 3, fp1);
ptr2 = fgets(ptr2, 3, fp2);
sum[i] = atoi(ptr1)+atoi(ptr2);
printf("%d\n",sum[i]);
}
fputs("begin", fp3);
for(i = 0; i < 9; i++)
{
fputs(" ", fp3);
sprintf(ptr3, "%d", sum[i]);
fputs(ptr3, fp3);
}
fputs(" ", fp3);
fputs("end", fp3);
fclose(fp1);
fclose(fp2);
fclose(fp3);
}
#include <stdlib.h>
#define MAX_SIZE 1024
int main()
{
FILE *fp1;
FILE *fp2;
FILE *fp3;
char s1[MAX_SIZE];
char s2[MAX_SIZE];
char s3[MAX_SIZE];
char *ptr1 = s1;
char *ptr2 = s2;
char *ptr3 = s3;
int sum[MAX_SIZE];
int i;
if((fp1 = fopen("text1.txt", "r+")) == NULL)
{
printf("open text1.h error!\n");
}
if((fp2 = fopen("text2.txt", "r+")) == NULL)
{
printf("open text2.h error!\n");
}
if((fp3 = fopen("text3.txt", "w+")) == NULL)
{
printf("open text3.txt error!\n");
}
fgets(ptr1, 6, fp1);
fgets(ptr2, 6, fp2);
for(i = 0; i < 9; i++)
{
fseek(fp1, 1L, 1);
fseek(fp2, 1L, 1);
ptr1 = fgets(ptr1, 3, fp1);
ptr2 = fgets(ptr2, 3, fp2);
sum[i] = atoi(ptr1)+atoi(ptr2);
printf("%d\n",sum[i]);
}
fputs("begin", fp3);
for(i = 0; i < 9; i++)
{
fputs(" ", fp3);
sprintf(ptr3, "%d", sum[i]);
fputs(ptr3, fp3);
}
fputs(" ", fp3);
fputs("end", fp3);
fclose(fp1);
fclose(fp2);
fclose(fp3);
}