. . , -.
- .
: , , . :
0 | 1 | 2 | EOF |
EOF , .
, . , . . 5 , :
stdin ( );
stdout ( );
stderr ( ).
.
. :
FILE *_;
, FILE *fp;
FILE , stdio.h. FILE , , : , () ..
, fopen(). . :
_=fopen(_, _);
fopen() , , . ,
fp=fopen(test.dat,r);
test.dat , fp. r , .
:
r
w
a
r+
w+
a+
. , . .
, .
: , ( 13) ( 10). , \n .
|
|
. , .. .
. , b. , rb, wb r+b. t, .. a+t rt.
- , fopen() NULL. stdio.h. - , .. :
FILE *fp;
If (fp=fopen(test.dat,r)==NULL
{ puts( \n);
return; }
.
fclose(), :
int fclose(FILE *fptr);
fptr . , . .
putc()
int putc(int ch, FILE *fptr);
, . EOF.
, , gets()
int gets(FILE *fptr);
. , EOF. EOF.
gets() int. ch puts(). . char.
1. , . *.
//
# include <stdio.h>
void main()
{ FILE *fp; char c;
if ((fp=fopen(test.dat,w))==NULL)
{puts( ! \n); return;}
puts( . *);
while ((c=getchar())!=*) putc(c,fp);
fclose(fp); }
( , ) test.dat, . * .
2. .
//
# include <stdio.h>
# include <conio.h>
void main()
{ FILE *fp; char c;
clrscr();
if ((fp=fopen(test.dat,r))==NULL)
{puts( ! \n); return;}
while ((c=getc(fp))!=EOF) putchar(c);
fclose(fp);
}