. -. , .
-, FILE, stdio.h. FILE .
fopen(), FILE, .
FILE *fopen (name, type);
name ( ),
type - , :
"r" ( );
"w" ; , ;
"a" ( ); , ;
"r+" ( );
"w+" ; , ;
"a+" , , .
- . , NULL.
fclose() , fopen() . fclose().
: 0, ; EOF, .
#include <stdio.h>
int main()
{
FILE *fp;
char name[]="my.txt";
if(fp = fopen(name, "r")!=NULL)
{
// ?
... //
}
else printf(" ");
fclose(fp);
return 0;
}
:
char fgetc();
FILE. . , EOF.
:
fputc(,);
FILE. .
fscanf() fprintf() scanf() printf(), , .
fscanf(, " ", );
fprintf(, " ", );
fgets() fputs() - , gets() puts() .
fgets( , , );
, '\n', , EOF . - '\0'. .
fputs( , );
. - .
s1.txt. s1.txt, 3 s2.txt.
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *S1, *S2;
int x, y;
system("chcp 1251");
system("cls");
printf(" : ");
scanf("%d", &x);
S1 = fopen("S1.txt", "w");
fprintf(S1, "%d", x);
fclose(S1);
S1 = fopen("S1.txt", "r");
S2 = fopen("S2.txt", "w");
fscanf(S1, "%d", &y);
y += 3;
fclose(S1);
fprintf(S2, "%d\n", y);
fclose(S2);
return 0;
}