Stdin, stdout
1 scanf(%d,& num); fscanf(infilep,%d,& num);
↓ c: data.txt
num
. 12 data.txt
(: )
2 printf(n=%d\n,num); fprintf(outfilep,n=%d\n,num);
3 ch=getchar(); ch=getc(infilep);
4 putchar(ch); putc(ch,outfilep);
:
c:\tc\2.txt i,j, c:\tc\1.txt i,j
#include<stdio.h>
main()
{
int i,j;
FILE *inf,*outf;
Outf=fopen(2.txt,w);
Inf=fopen(1.txt,r);
i=1;
j=2;
fprintf(outf,%d%d,i,j);
fscanf(inf,%d%d,&i,&j);
printf(%d%d,i,j);
fclose(outf);
fclose(inf);
}
1.txt
34 56
i j
2.txt
1.2
c:\tc\
3456
Fff_1
#include <GRAPHICS.h>
#include <conio.h>
#include <stdio.h>
main(int argc,char*argv[])
{
int i,j;
FILE *inf,*outf;
if(argc==0){printf(yk imja bx byx file);exit(-1);}
outf=fopen(argv[2],w);
inf=fopen(argv[1],r);
i=1;
j=2;
fprintf(outf,%d %d,&i,&j);
fscanf(inf,%d%d,&i,&j);
printf(%d%d,i,j);
fclose(outf);
fclose(inf);
}
fff_1.exe 1.txt 2.txt
. .
1.txt 2.txt
34 56 1 2
Options → Arguments
fff_2
#include <GRAPHICS.h> -
#include <conio.h>
#include <stdio.h>
main(int argc, char *argv[])
{
int i, j, i7;
char a[6], b[6[;
FILE *inf, *outf;
if(argc==0) {printf(yk imja bx byx file);
exit(-1);}
outf= fopen(argv[2],w);
/* outf=fopen (2.txt,n); */
inf=fopen(argv[1],r);
/* inf =fopen(1.txt,r); */
for (i7=1; i7 <4; i7++)
{
fscanf(inf, %d%d%s%s,&I,&j,a,b);
fprintf(outf, %d%d%s%s\n,I,j,a,b);
}
fclose(outf);
fclose(inf);
}
fff_2.exe 3.txt 5.txt
3.txt 5.txt
34 56 aaa fff
56 78 bbb nnn
11 3 ccc ddd
Fff_4
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
main(int argc, char *argv[])
{
int i, j, i7;
char a[6], b[6];
FILE *inf,*outf;
if(argc==0) {printf(yk imja bx byx file);
exit(-1);}
outf=fopen(argv[2], w);
inf=fopen(argv[1], r);
while(feof(inf)==0)
(* *)
{
fscanf(inf,%d%d%s%s\n,i,j,a,b); fprintf(outf,%d%d%s%s\n, i, j,a,b);
}
|
|
(* feof(inf)
= 0
≠ 0 *)
fclose (outf);
fclose (inf);
}
fff_4 3.txt 7.txt
.
fread fwrite . .
fread (, , , )[;]
. . , . .
, Dic F:
fread (&Dic, sizeof(Dic), 1, F);
, , 1. 0.
fwrite ( , , , );
. fread. . , DicStr:
fwrite (Dic,sizeof(DicStr), 1, F);
( ).
fseek ( , , )[;]
, , .
,
:
SEEK-SET ;
SEEK-CUR ;
SEEK-END .
0. , fseek .
ftell ( )[;]
. ( ) .