文件(I/O)

c语言

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 100


int main(){
FILE *fp1=fopen("input.txt","r");
FILE *fp2=fopen("output.txt","w");

if(fp1==NULL||fp2==NULL){
printf("打开文件失败!");
}
int a[MAXSIZE];
int b[MAXSIZE];
int i=0;
int n=0;
fscanf(fp1,"%d",&n);
i=0;
while(i<n&&fscanf(fp1,"%d",&a[i])!=EOF){
i++;
}
i=0;
while(i<n&&fscanf(fp1,"%d",&b[i])!=EOF&&i<n){
i++;
}
int k;
k = fun(a,b,n);

fprintf(fp2,"%d",k);
fclose(fp1);
fclose(fp2);

return 0;
}

input.txt

3
5 15 18
3 14 21