"r" "w" "" "r+" "w+" ''+" | / / / |
, test ,
fp = fopen("test", "w");
fp - FILE*. fp .
, , , , , :
if((fp = fopen("tesf, "w"))==NULL)
{
uts(" !\n");
exit(l);
}
NULL - , stdio.h.
putc()
uts(<>, fp);
, fopen(); fp - fopen() .
getc()
getc(fp)
, , fopen(). fp FILE, fopen(). , , getc() EOF. , :
ch = setc(fp);
while(ch!=EOF)
{
ch = getc(fp);
}
feof() - 1, , 0, . , , :
while(!feof(fp)) ch = getc(fp);
fdose() , fon(). . , .
fon(), getc(), putc() fdose() -. putc(), fon() fdose() , . x , $. . , ktod ( - ), ktod test test.
108
#include.h"
main(argc,argv) /*ktod - */
int argc;
char *argv[];
(
FILE *fp;
char ch;
if(argc!=2)
{
printf("B \n);
exit(l);
)
if((fp=fopen(argv[l], "w"))== NULL)
(
printf("He \n);
|
|
exit(l);
}
do
(
ch = getchar();
putc(ch, fp);
)
while (ch!='s');
fclose (fp);
}
dtos, ASCII .
109
#include "studio.h"
main (argc, argv) /*dtos-wicK */
int argc;
char *argv[];
(
FILE *fp;
char ch;
if(argc!=2) {
printf(" \n"};
exit(l);
}
if((fp=fopen(argv[l], "r"))==NOLL)(
printfC'He \n"};
exit(l);
}
ch=getc(fp); /* */
while(ch!=EOF)
{
putchar(ch); /* */
ch=getc(fp);
}
fclose(fp);
}
- fseek(), .
, 234- test :
funcl()
{
FILE *fp;
if((fp=fopen("test","r"))==NULL)
{
printf("He \n");
exit(l);
}
fseek(fp,234L,0);
return getc(fp); /* 234- */
}
- - fprintf() fscanf(). , printf() scanf(), , . fprintf() fscanf() :
fprintf(1,<>,< >);
fscanf(1,<>,< >);
fp , fopen().
- , , , , .
- , #, .
.
:
#include
#define
#pragma, #if, #error .
- . , , , - , .
,
#include <stdio.h>
, stdio.h, , -. math.h. , , string.h, - stdlib.h, - time.h, - assert, h ..
|
|
#define ( ).
#define <> < >
#define <(< >)> < >
- . - . .
, () , , .
,
#defmePI3.14159
#defineE2.711828
PI .
, . ,
#define forever for(;;)
forever
. - , . , .
. .
.
1: .
110
#include<stdio.h>
#define MAX(X,Y) ((X)>(Y)? (X): (Y))
main()
{
int x,y;
scanf ("%d %d", &x, &y); printf ("%d", MAX(x, y));
)
:
3 5
2.
111
#include<stdio.h>
#define S (x) x*x
#define P(x) printf("x %d.\n",x)
main()
{
int x=4;
int z;
z = S(x); P(z); z = 3(2);
P(z);
P(S(x));
P(S(x+2));
P(100/S(2));
P(S(++x));
}
:
x 16.
x 4.
x 16.
x 14.
x 100.
x 30.
#pragma ( ). ,
#pragma recursive
#pragma nonrec
.
#pragma optimize time
, , , , .
, , : , . . , , .., - , , , , , .
, ( ) - , ( ), .. , ; . , , , , , ; , . , . . , , ; , , , , ( ).
|
|
, . , , . - , . , .
1. .
2. ?
3. , , ? .
4. ? .
5. , .
6. ?
7. ?
8. for. .
9. ? .
10. ?
11. ? ?
12. ( , ).
13. ? .
14. ?
15. ?
16. .
17. ? .