- 在线时间
- 0 小时
- 最后登录
- 2007-9-23
- 注册时间
- 2004-9-10
- 听众数
- 3
- 收听数
- 0
- 能力
- 0 分
- 体力
- 9975 点
- 威望
- 7 点
- 阅读权限
- 150
- 积分
- 4048
- 相册
- 0
- 日志
- 0
- 记录
- 0
- 帖子
- 1893
- 主题
- 823
- 精华
- 2
- 分享
- 0
- 好友
- 0

我的地盘我做主
该用户从未签到
 |
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(p开头)</FONT></B></FONT>; U) S y5 Q. {3 P
</P>+ u- L* |# c8 D5 B
< ><FONT color=#ff0000>函数名: parsfnm </FONT>: a: R7 M, e4 i }; b
功 能: 分析文件名 }! h% F2 ]& ]; T
用 法: char *parsfnm (char *cmdline, struct fcb *fcbptr, int option); , b7 n, u8 C1 O8 \: O+ i. q% i
程序例: </P>
/ R/ A+ y9 N* c* v( `3 c0 S7 o< ><FONT color=#0000ff>#include < ROCESS.H>
7 m5 T! a# v4 S4 ^# o& `#include <STRING.H>) i2 Q4 `! J+ J0 [& k
#include <STDIO.H>3 V( m% S1 g3 r9 L, E
#include <DOS.H></FONT></P>
) E v5 H( _! P; [, {; h$ l4 a+ u0 ^< ><FONT color=#0000ff>int main(void)
; u, u# z4 }, z$ J! J. S% g0 {{
) ?; h- i: n! q @7 Xchar line[80];
! Y: h7 j" t$ o/ q& fstruct fcb blk; </FONT></P>5 F& }& V4 e* E( ^: B2 z
< ><FONT color=#0000ff>/* get file name */
S* F# t9 X" `/ H M; Iprintf("Enter drive and file name (no path - ie. a:file.dat)\n");
8 i5 T' t5 \# Cgets(line); </FONT></P>
' ^8 f' W' k+ k/ d e& b! e% ~9 z< ><FONT color=#0000ff>/* put file name in fcb */ y1 R4 ]: t! x* a; M
if (parsfnm(line, &blk, 1) == NULL) 7 a& k P3 [- g& x7 M# |- i+ Y
printf("Error in parsfm call\n"); 2 d% S7 P9 s' h5 O& P
else
! D9 G- a, Z' W8 o; Mprintf("Drive #%d Name: %11s\n", blk.fcb_drive, blk.fcb_name); </FONT></P>/ e( a l' e# u! r6 o
< ><FONT color=#0000ff>return 0;
) ?* d; X3 S. Y. i2 h2 m9 p( G}
. L9 Z1 M7 h E! X* x( ~/ [7 r# ~" ~( Y
</FONT></P>3 V" o$ I+ V7 r$ L, c2 c* l
< ><FONT color=#ff0000>函数名: peek </FONT>; y3 T s# F* e3 E. l$ G: z4 d
功 能: 检查存储单元 g. W! F+ m- N0 B9 F! J
用 法: int peek(int segment, unsigned offset);
# V. I0 z, P @程序例: </P>
: i! m: s8 Y! ?. A, A- I< ><FONT color=#0000ff>#include <STDIO.H>
1 g% W( `/ C2 k# z* X7 u) o#include <CONIO.H>' J& v7 R8 V* P2 }2 l
#include <DOS.H></FONT></P>
6 y# z1 Z& a7 K4 Z0 o0 ^, L< ><FONT color=#0000ff>int main(void)
, ^" ^% z4 |" ?) S( d# z- N X% W{ . F% r8 \: b+ g: ]- R
int value = 0; </FONT></P>
% @2 D' K2 f1 I. X2 F& N# w, m' ?< ><FONT color=#0000ff>printf("The current status of your keyboard is:\n"); 5 H p1 u A1 ?2 E6 h
value = peek(0x0040, 0x0017); ; T$ r" I- X- V' Y- U4 f- F: Z# f
if (value & 1) : p; J: Q$ E0 \
printf("Right shift on\n"); 2 k& d6 X$ D/ {$ u/ k+ }7 D" a
else 8 U4 H0 |' ^ e3 t1 s, [
printf("Right shift off\n"); </FONT></P>
! B8 U1 p) S0 F8 Y1 A! y* J< ><FONT color=#0000ff>if (value & 2)
8 g0 {# K. R/ ?6 Pprintf("Left shift on\n");
$ A( }& L. u, h6 S# relse
4 |/ a0 _* Z; w* {& Iprintf("Left shift off\n"); </FONT></P>
7 s1 J! _9 f' B8 e$ M( y3 @8 R< ><FONT color=#0000ff>if (value & 4)
6 N; f, y! s( I; E8 pprintf("Control key on\n");
; a6 r% K4 U9 S' a- I8 `else
6 S/ G, ^, M6 h( ?+ J+ ^printf("Control key off\n"); </FONT></P>$ k' N) `" a( A) D2 M/ {$ d8 F, ~
< ><FONT color=#0000ff>if (value & 8)
_7 |0 Y2 V9 E+ L, [5 n0 ]! I. Mprintf("Alt key on\n");
' _' o% f! _8 o0 ?else # y, M' A. |+ ~
printf("Alt key off\n"); </FONT></P>7 m9 Q I. c- E" [; M$ o$ ~
< ><FONT color=#0000ff>if (value & 16) : v/ d8 [& c F
printf("Scroll lock on\n");
. K3 Q! x {8 l& E- W7 b/ helse
7 I" X* R: ?, Z* cprintf("Scroll lock off\n"); </FONT></P>! q% D3 U( R, f7 M! [. v% a
< ><FONT color=#0000ff>if (value & 32)
6 V5 q$ [3 P, S7 c4 E4 |printf("Num lock on\n");
6 m& n. Q; y& s$ {else
; L2 L1 x) O B5 V: ~( X* Xprintf("Num lock off\n"); </FONT></P>6 u2 v# W: ~4 b' n
< ><FONT color=#0000ff>if (value & 64) + A1 Z% H9 ]- W0 `
printf("Caps lock on\n");
k4 k- `$ e/ P/ f3 Relse
" P+ L' Z7 b& n! b6 n+ c2 E- z) `printf("Caps lock off\n"); </FONT></P>6 r/ M+ c3 ?# x+ X" n
< ><FONT color=#0000ff>return 0;
/ v& a& H# B* j2 s6 j# d} / S7 S3 m' v. m' F5 Z6 e. B2 C
1 }: w5 C0 c; D, f! p3 l</FONT></P>
, G/ Z: ^( u( o0 F/ j3 C. E< ><FONT color=#0000ff>函数名: peekb </FONT>
9 {" B) n8 c% K# ^. i9 E功 能: 检查存储单元
6 u5 F; z S ~7 D& k2 |9 a用 法: char peekb (int segment, unsigned offset);
+ \" g2 S4 I5 h8 E$ P; p程序例: </P>
2 }( J6 [- [% W+ F& i R$ V ~< ><FONT color=#0000ff>#include <STDIO.H>
6 A- [0 r5 }# M7 s$ d4 u2 K#include <CONIO.H>1 W: t8 B- w. F& f$ t+ M5 z
#include <DOS.H></FONT></P>+ y: U' F, V' {9 y3 d* E# T3 P; u, D
< ><FONT color=#0000ff>int main(void) & R: r! X b M
{ , F* @ k+ c7 ` E( _' ?
int value = 0; </FONT></P>/ }. ^9 A$ u' Y" k) Q F
< ><FONT color=#0000ff>printf("The current status of your keyboard is:\n");
$ {- E! s2 |! a3 Kvalue = peekb(0x0040, 0x0017);
: a# i' J2 |/ V3 x* y& J0 x5 `2 |if (value & 1)
?) S6 o" A; a. _0 E& X6 S5 Nprintf("Right shift on\n");
2 _- ^6 s, h/ ~0 I2 ?5 ^else
* u+ b/ D+ \+ q) e% N/ @printf("Right shift off\n"); </FONT></P>
( H* G( [2 ~7 p( Y- R& U3 I( K< ><FONT color=#0000ff>if (value & 2) X0 |9 e z; f6 q( {. P
printf("Left shift on\n"); % f' ~( e3 F; [; a/ y, R- Q
else ! F n' f+ q+ u2 n# B4 @
printf("Left shift off\n"); </FONT></P>
% p( N" B* ]. V* m4 p6 G) [/ F5 s# O< ><FONT color=#0000ff>if (value & 4)
+ ?; g- j9 G, s1 n& g% ]3 |' Zprintf("Control key on\n"); ( v, R4 ?: o- M
else
+ B8 x9 J1 l5 uprintf("Control key off\n"); </FONT></P>
. z2 ~/ K, m4 j! ~1 P f+ X: A< ><FONT color=#0000ff>if (value & 8) , e2 J/ p: a' \" o+ ~
printf("Alt key on\n"); , j$ h2 p# i. a3 T! v
else & A: y1 v( ?3 F$ r/ \( |% O
printf("Alt key off\n"); </FONT></P>9 [. n. ?" x; T! N
< ><FONT color=#0000ff>if (value & 16) ! S, X( K0 _3 Z' J2 z5 f' }8 q
printf("Scroll lock on\n"); % ^# t+ O& N( V+ C. d0 b, k4 R, e
else
: k+ z( ~( J% F4 P# i( P$ R. Cprintf("Scroll lock off\n"); </FONT></P>5 q! x; s9 C9 T0 T
< ><FONT color=#0000ff>if (value & 32)
, r1 g( _ ~+ b2 |printf("Num lock on\n"); ! ~* w* i. x9 A8 \. P" [. L4 r
else 9 q! j; A8 X. N2 m8 @( O
printf("Num lock off\n"); </FONT></P>% X* I' Z! V7 e L1 N8 u
< ><FONT color=#0000ff>if (value & 64) - i1 z7 M6 H+ F) @3 ?
printf("Caps lock on\n");
0 d: e: U0 C! h; `3 Telse
7 }' }0 w( u$ g' Lprintf("Caps lock off\n"); </FONT></P>
' f( c& ^; G8 B/ s) m2 A; g- t! j< ><FONT color=#0000ff>return 0;
. c c8 V$ Y" T# I! r$ w" D} . w- m+ }. h$ r' F2 z @: K
</FONT>
5 Z# @8 |+ r2 x5 o% z</P>
, u+ z+ |+ b1 Q/ O<P><FONT color=#ff0000>函数名: perror </FONT>+ _. d; c( D/ R, J. M& b3 B
功 能: 系统错误信息
8 b9 k. b" x7 P# L用 法: void perror(char *string); - l- S6 u2 [4 M1 O& o8 c' e
程序例: </P>
) k0 G2 p# S* C: ], `2 V<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>1 u0 S* \8 B6 m% `5 \" E5 K+ D
<P><FONT color=#0000ff>int main(void) % n6 d% \9 R# |# N$ _% q2 v C1 ^
{
' R- h) I$ I1 I7 F7 k- L, _FILE *fp; </FONT></P>
, ?1 t! b4 S1 t) { z) ^9 }<P><FONT color=#0000ff>fp = fopen("perror.dat", "r");
1 {) B: U7 b( p0 G/ ~- |9 @: Mif (!fp)
2 @7 o6 L9 [. ~/ x$ qperror("Unable to open file for reading");
5 Z3 z7 M- a2 n7 h3 }$ x" N) a- Jreturn 0; ( `( X6 s) \% S5 P) T& H8 q
}
: x! B, t R$ t% @4 K- x$ K2 o) C! z5 ]* t
</FONT></P>
( |: k7 ^7 f% h! _! @& x<P><FONT color=#ff0000>函数名: pieslice </FONT>
9 c2 |7 x0 q9 l3 v3 b- |! T3 E" q+ W功 能: 绘制并填充一个扇形
: t0 W; D) U7 I- p) ?% l$ u用 法: void far pieslice(int x, int stanle, int endangle, int radius); . S) V% x3 h" M+ {7 d; U+ \
程序例: </P>
! j- i U2 \0 s# K/ G2 L<P><FONT color=#0000ff>#include <GRAPHICS.H>8 T6 i# t0 F; [; E9 r0 A( P
#include <STDLIB.H>2 c, a& j9 _( R# j4 z1 k
#include <STDIO.H>, H/ N1 F8 `8 w; V2 ]
#include <CONIO.H></FONT></P>
+ |- U. _. @5 E/ O4 I2 u0 W. t. q<P><FONT color=#0000ff>int main(void)
" ~% b- M5 z: n0 G" Y% P7 B{ : y& O- s8 a) j/ c# \$ T( y
/* request auto detection */ * D! n+ w( q" h/ h4 O: [# O# B8 d
int gdriver = DETECT, gmode, errorcode; - Y+ u" ]& A t7 x
int midx, midy; 4 B! D) l- I. |/ x* N
int stangle = 45, endangle = 135, radius = 100; </FONT></P>* l- F4 w9 D0 g
<P><FONT color=#0000ff>/* initialize graphics and local variables */
; Z# p% ]6 M7 Ginitgraph(&gdriver, &gmode, ""); </FONT></P>
5 o0 a+ n8 |: I! n* Q$ d) V<P><FONT color=#0000ff>/* read result of initialization */
$ Y* |3 p# D: {errorcode = graphresult(); : K7 p# h2 R; m+ n
if (errorcode != grOk) /* an error occurred */
9 f ^% u1 p; \# S0 \{
$ w& K; Z8 R) X+ t4 lprintf("Graphics error: %s\n", grapherrormsg(errorcode)); : G- G: {; ^2 [2 Q" [
printf("Press any key to halt:");
2 ~ i) z, d3 U, u2 [% D% B* Kgetch();
6 Z) Q/ M1 ]& Qexit(1); /* terminate with an error code */ . J) `9 _) k9 X$ B1 M' V( V- ?9 [/ d
} </FONT></P>4 B- ?& e6 Q/ z7 O
<P><FONT color=#0000ff>midx = getmaxx() / 2; # v) R6 }: [. y2 @& y# c$ Z
midy = getmaxy() / 2; </FONT></P>
, E& C4 ?% s! ]3 _& U7 z' x4 z! g Y<P><FONT color=#0000ff>/* set fill style and draw a pie slice */ 5 Q* u1 X4 T& d# ~) ~
setfillstyle(EMPTY_FILL, getmaxcolor());
: V9 B7 H1 w7 M( S& O% i* n1 upieslice(midx, midy, stangle, endangle, radius); </FONT></P>
- K0 }* i( v2 t1 t- p" g<P><FONT color=#0000ff>/* clean up */ : a. w% K& ^% y# e5 Y( s
getch();
0 a2 F9 O$ O, ]- i: X0 j; Hclosegraph(); ! b7 ?- m/ q! ~" V
return 0;
" b9 i3 j1 G- b/ U} </FONT>* f1 e+ w4 l1 ]+ Q z2 R% @. N P3 e
/ z( ]( {0 F1 }. A8 \</P>! ^5 E$ e0 p# B6 {0 M
<P><FONT color=#ff0000>函数名: poke </FONT>
0 u: f# y) W* x& \6 q功 能: 存值到一个给定存储单元 ( P* U5 J! P/ [6 T8 \
用 法: void poke(int segment, int offset, int value);
) o& y$ U8 P) o, b程序例: </P>5 h" a. Z8 p: N' ]" Z" ^2 [! \0 Z
<P><FONT color=#0000ff>#include <DOS.H>
2 u9 q6 D% o% M, V1 z; ^- ~#include <CONIO.H></FONT></P>
8 s) W+ U/ C1 U9 }) b7 C& Z<P><FONT color=#0000ff>int main(void)
) x! l) h: ]& A. {: N: a{ b+ {2 r2 V8 _& i9 [9 ~
clrscr(); / S7 C% H8 M% A, O% c
cprintf("Make sure the scroll lock key is off and press any key\r\n");
4 Y& J/ x3 O/ l4 Zgetch();
& {+ f: B) Y2 H, a8 b- O! ypoke(0x0000,0x0417,16);
; ], {9 Y- e; L+ f" Y2 d G+ ?cprintf("The scroll lock is now on\r\n"); 8 G( s7 j4 `; r! K; y0 Y9 a' M- R
return 0; , B/ ]' d. W& q8 E7 O) R
} 0 |; s/ K/ t3 k& \ y3 A
n- P! a2 L e3 s- t5 ~* F
</FONT></P>
& {5 |) c' u) I# f<P><FONT color=#ff0000>函数名: pokeb </FONT>
( G1 R" E/ z. K; b' ^$ a功 能: 存值到一个给定存储单元
. @+ E$ p; ?. b用 法: void pokeb(int segment, int offset, char value);
* D, s- i3 f# V/ F* K8 E# j0 L( n程序例: </P>9 r# F; O, m1 K8 C% y C
<P><FONT color=#0000ff>#include <DOS.H>
0 j$ q# |+ O' v- b' a; x#include <CONIO.H></FONT></P>9 I6 V/ s: e) p( K$ z
<P><FONT color=#0000ff>int main(void)
) } e7 t3 u* N( q. W- Z{ : g* E( }+ R. e# a9 ?% A, R0 L
clrscr(); 1 I: o+ L, `) ^& }
cprintf("Make sure the scroll lock key is off and press any key\r\n");
) t4 J! ^+ @0 N, s: o9 N9 B, g2 }' H8 q1 ~getch(); , x. Z( x9 O8 w7 H1 h8 q/ x+ y) y
pokeb(0x0000,0x0417,16); 9 ^ x( I5 ~ v
cprintf("The scroll lock is now on\r\n");
! z. ~$ n% P. ?9 d7 Dreturn 0; # N |1 m8 c; j7 ~8 x2 s* k
} </FONT>% E# n9 e' Q, d, X7 j7 f
- ~/ S9 ?8 o- @( Y
</P>
" F% l! ?" p: t7 J% c<P><FONT color=#ff0000>函数名: poly </FONT>9 {: [" ?" J5 Q# l7 j' t
功 能: 根据参数产生一个多项式 ; D0 e; s |# M2 c7 P$ w& g6 ^
用 法: double poly(double x, int n, double c[]);
! g( V' q, R- q* Q) K程序例: </P>& h; n+ K1 b( @( ^
<P><FONT color=#0000ff>#include <STDIO.H>
. V! h5 [' ?/ V8 p6 h/ f#include <MATH.H></FONT></P>* H( ^( f5 z# u7 h1 f" W. s
<P><FONT color=#0000ff>/* polynomial: x**3 - 2x**2 + 5x - 1 */ </FONT></P>
! ^+ _* h) A% p5 [+ M& f<P><FONT color=#0000ff>int main(void) . l5 M# J& W/ M' Y; [- H4 n
{ # p/ J/ D. o0 B' o
double array[] = { -1.0, 5.0, -2.0, 1.0 }; # p: G+ f! a$ e1 \7 H
double result; </FONT></P>' q" b# H* p' [8 {; K1 j+ Z: v6 {
<P><FONT color=#0000ff>result = poly(2.0, 3, array); 1 I6 B# s0 G- B0 k# M. ]
printf("The polynomial: x**3 - 2.0x**2 + 5x - 1 at 2.0 is %lf\n",
) b( c1 F, E0 z. zresult);
6 {5 \1 V2 m9 g4 k0 d9 A) c' Qreturn 0; 8 e* y _8 t; e! Y
} </FONT>
; r4 H0 T+ p: b7 b% P; I" n. ~. `3 D7 u* P* W. O
</P>
8 a m# x9 y, P4 H" D& P<P><FONT color=#ff0000>函数名: pow </FONT>
& ]! i/ ]7 l, E0 j. l; L6 s功 能: 指数函数(x的y次方) ' D$ l6 ^/ {7 z3 \4 ^
用 法: double pow(double x, double y);
& B6 w, @/ z( s- _. z程序例: </P>( o, h+ C/ x* N! y6 j9 A6 O
<P><FONT color=#0000ff>#include <MATH.H>
$ Y: A/ P" y4 Y- d#include <STDIO.H></FONT></P>. [& o( D6 m5 ~4 X ]/ x
<P><FONT color=#0000ff>int main(void) : C. h& s/ O9 o8 g C" X3 ?0 Q
{
( E, ~- `' ^ P6 Bdouble x = 2.0, y = 3.0; </FONT></P>
7 g1 ^; o' u4 f; r# F<P><FONT color=#0000ff>printf("%lf raised to %lf is %lf\n", x, y, pow(x, y));
( J6 [) V7 [- K& Breturn 0;
# | `8 c! |5 Q: v. a} h3 z' m- E/ S4 C6 P
</FONT></P>
% q: ~% [* m( N, m! j& z T<P><FONT color=#ff0000>函数名: pow10 </FONT>
. H6 @# Y& u$ N3 O6 N功 能: 指数函数(10的p次方)
. h( U: B8 I$ b( J! \! E% `用 法: double pow10(int p);
3 Y2 V) u! N! l$ V: b程序例: </P>
2 w+ Z/ {. |, j$ I" c<P><FONT color=#0000ff>#include <MATH.H>! @: l2 s9 q0 ^5 `' U$ a
#include <STDIO.H></FONT></P>$ ]4 e4 W( r3 i0 D4 l
<P><FONT color=#0000ff>int main(void)
- J. m3 U2 n9 y& G* \: i& U8 b{
, x0 g) M$ E4 v$ ~) X! g- Sdouble p = 3.0; </FONT></P>
; B" n! h' G* f<P><FONT color=#0000ff>printf("Ten raised to %lf is %lf\n", p, pow10(p));
3 m$ ~1 v5 d% z' v4 Zreturn 0;
7 Q" W6 k- W5 v$ \- C: n5 a' a$ Q} </FONT>
4 C6 l% [" X) w* A' m/ v, ^; [
5 s" n& Q/ [+ `0 Y; E9 W</P>
% J7 F# ?: z& x7 O7 n2 r<P><FONT color=#ff0000>函数名: printf </FONT>: }6 c( s6 C' i- W' f5 u! }
功 能: 产生格式化输出的函数
* H+ h) X* B# O5 j用 法: int printf(char *format...);
5 o" \* T% m( o% `程序例: </P>
0 }) I& W5 t7 y. f5 M<P><FONT color=#0000ff>#include <STDIO.H>
! C' n$ S$ |: V$ K#include <STRING.H></FONT></P>8 z# [1 {: P3 A6 f
<P><FONT color=#0000ff>#define I 555
W+ f3 f* b1 h# J( G/ [: b#define R 5.5 </FONT></P>' ?7 g! @! t2 {+ p6 L7 b2 G
<P><FONT color=#0000ff>int main(void) 6 U/ ?% A& _# Z, {! I* b
{ : h9 D1 W. K' `& o
int i,j,k,l;
: u! w r n) J7 X6 A# {# Mchar buf[7]; o+ s- {. }1 d9 A( R1 X7 i( Y
char *prefix = buf; 0 Q& k; q; W7 o9 Z% G
char tp[20]; * J4 s& J# e5 Q- \& J4 ~, q, }- W5 ?+ K
printf("prefix 6d 6o 8x 10.2e "
0 U- I/ p* ]" b1 w `"10.2f\n");
0 z% C1 h0 Z) p& a1 c6 I4 {strcpy(prefix,"%"); ( t: a* V8 a5 E# k
for (i = 0; i < 2; i++) , G: u8 U6 K5 V {& w% O4 D
{
z0 ^9 w: g: D( |, N% {+ Yfor (j = 0; j < 2; j++) # E# i4 j# K! r# o/ u6 O; r! c
for (k = 0; k < 2; k++)
# {, ^5 B3 ^6 U$ ?for (l = 0; l < 2; l++)
4 ?& @+ n4 T d; ~{
( P( [' V" ]: V# k, Yif (i==0) strcat(prefix,"-"); 4 H7 n n0 R% }/ S0 _( }
if (j==0) strcat(prefix,"+"); 1 S5 g( L: L8 f& W% T, p
if (k==0) strcat(prefix,"#"); # G, B/ X' p# t+ P8 K
if (l==0) strcat(prefix,"0"); & a8 I5 O0 Q. ~: |' n
printf("%5s |",prefix);
& q3 Z0 k4 O k% D6 {4 c8 \strcpy(tp,prefix);
8 C5 Y9 t4 T6 {- M( Bstrcat(tp,"6d |");
/ z8 [" P5 s% T6 n$ X: Q* Oprintf(tp,I);
+ K; D9 A* _6 T& _5 m& e @strcpy(tp,"");
* i& A5 d1 K" w: [strcpy(tp,prefix); + h: ]/ M, k2 o$ D( i
strcat(tp,"6o |");
3 y3 K; s+ f& a; ]printf(tp,I); ; a& n3 \* X+ q5 J
strcpy(tp,"");
) j6 H& d! [, \5 [" ?8 p4 s' F2 I) _strcpy(tp,prefix);
) b( L. V: m0 C( \: qstrcat(tp,"8x |");
2 v" h/ V1 r, Qprintf(tp,I);
" }7 u U+ m2 j" I+ l# ~strcpy(tp,"");
1 d# F9 P' r9 J N7 mstrcpy(tp,prefix);
. {0 ~5 y) I" N5 tstrcat(tp,"10.2e |"); ; Q$ d( E( L9 [, ~9 S' b! S8 ~) A
printf(tp,R);
% ?6 F: I. g' @+ Istrcpy(tp,prefix); , M4 Z- c* G0 ]9 G
strcat(tp,"10.2f |");
, X/ a+ U. ?/ Z: Y2 B0 B5 Fprintf(tp,R);
; q! h$ G0 }4 i1 wprintf(" \n");
9 O0 d' |/ n5 ustrcpy(prefix,"%");
% \4 b# w7 |& q" n k: v} % k% h5 N; c% t
} + C/ @; L8 B' z: `1 t( h7 a; |9 G
return 0;
' `& [3 h: Q% |, [+ L# J% i% `} </FONT>, v Q6 c D& o% |
3 c( `- h6 i- K) B
</P>0 S* t6 O; L8 ]; m9 ]3 x& ^
<P><FONT color=#ff0000>函数名: putc </FONT>
; E2 b9 _# `, f2 D; }- u% }功 能: 输出一字符到指定流中
; F Z8 U: [/ M1 p2 H' S8 F, `用 法: int putc(int ch, FILE *stream); # }, P, G6 N1 w3 H% O( A
程序例: </P>) d7 F8 r% Y* G: K( [9 m
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>, _2 s/ r: m \2 }% G4 Q* c
<P><FONT color=#0000ff>int main(void)
0 @: U% H) ^: |' m% J{ 8 J) f0 ^: \( n6 C" v9 d; p% {, j; B
char msg[] = "Hello world\n"; * L; J( w% G4 r( `" Y4 Y8 [ h
int i = 0; </FONT></P>/ p; L! M0 G/ U3 a+ b
<P><FONT color=#0000ff>while (msg)
) P: b" r& U9 D4 H4 H# ~! h. {putc(msg[i++], stdout);
7 y; ]# c5 r: R; S7 ^0 G: greturn 0; 3 |4 p2 m. B+ d. w" h8 A* s8 H
}
0 [/ o9 m. s3 y3 R& L% C8 {% S3 ^; O1 P( R$ v( {' F) Y
</FONT></P>9 v% \, i" Z! v b; f6 Z9 D
<P><FONT color=#ff0000>函数名: putch </FONT>
, g$ Z" { T v7 n+ ?! c功 能: 输出字符到控制台
/ N* h! U* Z' C% Q用 法: int putch(int ch);
, w4 ~1 I1 s. U/ ~$ j程序例: </P>
0 ^7 W. p/ l( P4 D) x( ]<P><FONT color=#0000ff>#include <STDIO.H>
3 ~( C" z; b ?8 \. H. y- e' ?( N; M#include <CONIO.H></FONT></P>
) J' v: _1 _2 \7 @- y# I( o0 |8 m<P><FONT color=#0000ff>int main(void)
+ }% x& [- k$ e, F. Q3 h{ ' k m! b( @* W( P9 F
char ch = 0; </FONT></P>
( ~5 ?- n: c: _2 ~% F7 u<P><FONT color=#0000ff>printf("Input a string:"); , B9 v( a1 @; @- k" l+ m
while ((ch != '\r'))
' B2 ?4 }3 ?& O$ ?3 P{
+ _; ^1 b$ g" K/ o+ ]8 \7 F# g% rch = getch();
6 W% U" w" A: \2 D3 cputch(ch);
2 t' _# N; z# p5 ^0 k% L} * e2 P( Y/ W$ r6 }; W4 y. Q
return 0;
% s; @! b' W' p: f Z. i& h}
, W8 w' J3 L& W1 A
$ |0 ~/ g' o/ D</FONT></P>
4 h, |* m5 h+ L3 w! m/ C<P><FONT color=#ff0000>函数名: putchar </FONT>
: E( Q5 ~& z( F9 H功 能: 在stdout上输出字符
3 n7 q4 ?9 {# m用 法: int putchar(int ch);
* _9 U2 c- g6 B- N程序例: </P>4 W+ P, h4 }! N2 p$ f, u& }6 [9 ^
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
; G1 Q: c m& l, c% [* a- |8 \<P><FONT color=#0000ff>/* define some box-drawing characters */
4 n9 h! l! U4 D#define LEFT_TOP 0xDA
4 L# X! P x+ |& [7 h#define RIGHT_TOP 0xBF ! ?8 f/ F7 q5 q9 h! N7 G$ W
#define HORIZ 0xC4 # @1 A7 \0 C" C2 Z
#define VERT 0xB3
% N7 u; ?7 C" t$ j4 N' G#define LEFT_BOT 0xC0
) {7 \+ }* [1 W! s! g4 E' }) R#define RIGHT_BOT 0xD9 </FONT></P>
6 ^* A' }& Q! y' s. d) o5 z3 b<P><FONT color=#0000ff>int main(void) 5 w0 ?& n: J& ?& J/ ]- z$ {5 A! l
{
% J3 F4 W( [" d0 W- Xchar i, j; </FONT></P>
0 _8 Y, i) K7 @0 h" |<P><FONT color=#0000ff>/* draw the top of the box */ - h6 j3 Y6 g( }
putchar(LEFT_TOP); # _$ k' E N5 J6 C3 b) y p: T
for (i=0; i<10; i++) o5 O; t' M0 w6 b, c
putchar(HORIZ); 6 K/ C$ ], Q* W: B* K/ I
putchar(RIGHT_TOP); 9 U9 R {. r! |! G1 ~& {4 I5 i" H
putchar('\n'); </FONT></P>* ?6 _9 V) P0 U* b
<P><FONT color=#0000ff>/* draw the middle */ 5 y4 y) x- }' r# ~1 S& ^ R% |
for (i=0; i<4; i++)
" h$ Y) `* e& _, M{
7 i% F: _5 S, z8 R, Vputchar(VERT); * a; ]! `3 N& ?7 x3 _+ b8 @
for (j=0; j<10; j++)
z& T6 F1 N; Z; cputchar(' '); " N4 H0 K: Q" [6 ]. l9 A
putchar(VERT); 4 j, y& Q" T4 B1 P2 H- [. Z
putchar('\n'); 8 o1 B* ]2 w; Y) R) K
} </FONT></P>! n2 m* d: H% h R, K
<P><FONT color=#0000ff>/* draw the bottom */
( W7 U4 }% i& s& d6 \1 Nputchar(LEFT_BOT); * a: ?) o. v; w. e4 j& V( ~6 X
for (i=0; i<10; i++)
; a( U3 A7 k Y1 r$ ^putchar(HORIZ);
, q# @% Z1 }. O9 O2 gputchar(RIGHT_BOT); - Q8 J- i0 x! }/ L2 L, L
putchar('\n'); </FONT></P>
% ?9 F ]" `! ~! W<P><FONT color=#0000ff>return 0; - F7 C3 c3 T' W' r5 x
} * i1 `( B" a3 ?' p
/ J- O' v- R% c% f5 U
</FONT></P>
( k+ f1 B0 h5 I( a' f2 W<P><FONT color=#ff0000>函数名: putenv </FONT>
' [0 n2 h* H% G' R( j功 能: 把字符串加到当前环境中
3 n9 |7 s$ y. p" o% z/ I用 法: int putenv(char *envvar); 4 j% R* o- V# I0 q8 Y1 Q5 {1 }
程序例: </P>2 ]4 S& d5 J( c8 u6 E' l
<P><FONT color=#0000ff>#include <STDIO.H>7 |4 T6 T8 O4 t
#include <STDLIB.H>3 i5 k$ w4 S+ q
#include <ALLOC.H>
/ o, i1 {& i: \& n+ a( X0 k#include <STRING.H>' P7 n6 I- }$ Z- c
#include <DOS.H></FONT></P># Y& z* w" _! {
<P><FONT color=#0000ff>int main(void) * A1 m. G' K2 V, C, [
{
) s: _3 S* I( g7 J2 k0 Zchar *path, *ptr;
* r. \4 A; w, o- ^ m" iint i = 0; </FONT></P>; @$ _% z- T' F0 d. i
<P><FONT color=#0000ff>/* get the current path environment */ # Q0 {% e6 ~( \$ U0 ]( e, K0 G/ q
ptr = getenv("PATH"); </FONT></P>
3 M$ F0 t$ |9 y1 N0 O' m8 S<P><FONT color=#0000ff>/* set up new path */ 0 ^5 Y0 M. Y' T5 W' ^
path = malloc(strlen(ptr)+15);
" Y3 ~1 D! L- y& o! y% ]strcpy(path,"PATH=");
, K9 y' \+ x# Fstrcat(path,ptr); 3 V1 j0 E2 D/ `9 J. a
strcat(path,";c:\\temp"); </FONT></P>& m- N# _9 ]! G; L
<P><FONT color=#0000ff>/* replace the current path and display current environment */ : k$ X: P* h" U0 @+ p( }+ ]9 i
putenv(path);
8 O5 I0 Q9 x7 h$ ?* J; \while (environ)
' c1 M/ c( H6 e6 ~- v4 P& Eprintf("%s\n",environ[i++]); </FONT></P>7 @! Z6 D/ m9 e& P* @
<P><FONT color=#0000ff>return 0; ; d: ?* y% Y2 W) c% Z
} 9 z- t0 [" {7 Z3 V* C) P, D0 |
</FONT>3 N$ H& R! ]7 `. B* U
</P>5 t4 `. W. a) Y
<P><FONT color=#ff0000>函数名: putimage</FONT>
! j5 I3 k. }! A9 v, }5 I: q功 能: 在屏幕上输出一个位图 6 a# f# _9 O) X$ k) z% N
用 法: void far putimage(int x, int y, void far *bitmap, int op);
! w" o3 g& i& v' J% j8 v程序例: </P>
% Z8 m$ D: p1 A5 U! H' i2 s6 {<P><FONT color=#0000ff>#include <GRAPHICS.H>+ w# u# C! y& w9 W4 }0 r/ q# @
#include <STDLIB.H>
5 K e3 l' A' s#include <STDIO.H>
( m/ S) F6 o* E( A#include <CONIO.H></FONT></P>$ n( V9 ], @- x5 e
<P><FONT color=#0000ff>#define ARROW_SIZE 10 </FONT></P>/ b5 M4 X2 q( j5 t, P" f
<P><FONT color=#0000ff>void draw_arrow(int x, int y); </FONT></P>( f6 i( v1 Z i* d% K
<P><FONT color=#0000ff>int main(void) 6 |% H; `/ B" Y$ w: o
{
0 E; ~6 W' d( V9 n2 b/ ]/* request autodetection */ 5 u5 K* J" l3 `* B/ B* f! Y
int gdriver = DETECT, gmode, errorcode; ) d% Z9 e" B( ?5 i" o3 ? _
void *arrow; ) d- L. B1 S' H6 |
int x, y, maxx; % S" f/ S# e9 n5 K1 v
unsigned int size; </FONT></P>
! c f3 g [& }0 N<P><FONT color=#0000ff>/* initialize graphics and local variables */
+ ~& G" S- y; @% S( s2 @) Kinitgraph(&gdriver, &gmode, ""); </FONT></P>
6 v1 h- f8 }4 |- \<P><FONT color=#0000ff>/* read result of initialization */ 9 e0 D$ u! l3 _- d) U4 t
errorcode = graphresult();
" r: [! V- M% ?$ ]7 k' A) G* lif (errorcode != grOk) /* an error occurred */ % m5 N. p2 v8 @' U0 R0 W
{ 8 v: X3 `5 n% R3 ^: u2 L
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 3 p% l% A n! f5 U1 h
printf("Press any key to halt:"); 8 M! G$ K8 A' b( }9 N$ k0 R6 I2 C! y
getch();
% F# T; G* g1 s$ k7 N+ fexit(1); /* terminate with an error code */
$ j1 O. c8 o5 l! I( W- |7 k} </FONT></P>
" m2 ?7 q" n3 q3 B/ q r<P><FONT color=#0000ff>maxx = getmaxx(); * H8 Q: c$ @0 @9 d o, q4 S
x = 0; ; |- J, g Z9 Y- V% L( M' v
y = getmaxy() / 2; </FONT></P>. l9 C1 H+ `% m# n1 s
<P><FONT color=#0000ff>/* draw the image to be grabbed */ 5 [% X" O- K, Y* i: Q! O! C- A
draw_arrow(x, y); </FONT></P>
# g7 k. e9 x9 O5 c9 u<P><FONT color=#0000ff>/* calculate the size of the image */
! ?& l/ o# W: B @size = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE); </FONT></P>
: @) l! b* A9 s0 ?$ v0 ]* h<P><FONT color=#0000ff>/* allocate memory to hold the image */ 6 ^* g3 |3 j* b
arrow = malloc(size); </FONT></P>1 l1 n. ^/ v+ t2 k
<P><FONT color=#0000ff>/* grab the image */ 4 ^& V) y# L6 p+ z5 C& V0 i$ a
getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow); </FONT></P>
: m) M9 E/ [1 p' p<P><FONT color=#0000ff>/* repeat until a key is pressed */
* k0 D$ z6 n' b% s3 Y. o2 \while (!kbhit()) 7 r, x% _# T# d7 r: d0 d" \
{
, ^% S% N0 P5 v/* erase old image */ . l8 y" F B% k q$ |
putimage(x, y-ARROW_SIZE, arrow, XOR_PUT); </FONT></P>" ], p4 E y# r* p
<P><FONT color=#0000ff>x += ARROW_SIZE; 0 N: c0 B" E, c: C+ _4 k
if (x >= maxx) # w3 E8 l( \2 o, b
x = 0; </FONT></P>" s( y6 |7 e2 A+ `
<P><FONT color=#0000ff>/* plot new image */
6 c9 H. t8 a% p2 y/ cputimage(x, y-ARROW_SIZE, arrow, XOR_PUT); h H2 [" O( C1 g) p
} </FONT></P>
: U3 \3 s% V0 t+ C<P><FONT color=#0000ff>/* clean up */
! ~1 f) X; r0 \6 J# ?+ [free(arrow); & ]7 n" c$ _2 w+ V# k+ I' O
closegraph();
) e- j& p6 y% \' Greturn 0;
8 _7 y1 l" T6 q# w$ M: Z+ ~} </FONT></P>
5 @9 h% Q6 K3 a3 u, [/ |8 ^<P><FONT color=#0000ff>void draw_arrow(int x, int y)
* Z# w' ~7 a% C; }" u% Y' X3 \{
' x4 y5 f- P( T' c2 W9 k/* draw an arrow on the screen */ ; `7 }. D9 L5 d5 M/ ^: ^0 n8 \9 g
moveto(x, y);
7 {8 v* n4 O7 M5 J. g. `# glinerel(4*ARROW_SIZE, 0); % P- N" S7 N9 b! b1 L9 Y$ G7 a
linerel(-2*ARROW_SIZE, -1*ARROW_SIZE);
0 n5 s5 \( V3 y0 Rlinerel(0, 2*ARROW_SIZE); * c# z+ d1 Q8 j# w1 {0 ^
linerel(2*ARROW_SIZE, -1*ARROW_SIZE); ! A( k& }1 S9 `' Y+ }! ?! o
}
# Z7 G1 @5 U/ d G3 d/ j: E0 i# ?0 f9 B- m
</FONT></P>6 k7 c. T+ N8 p' j, e: k
<P><FONT color=#ff0000>函数名: putpixel </FONT>
! q1 e" f( A P2 r) x4 b# U, V功 能: 在指定位置画一像素
! ?# Q9 n5 I6 v' {7 h9 I用 法: void far putpixel (int x, int y, int pixelcolor); 4 T$ C0 j- h7 v( z9 ]" B
程序例: </P>* o4 j- L( Y1 O9 e9 Z0 e3 [% ?
<P><FONT color=#0000ff>#include <GRAPHICS.H>; v6 w: [9 U% T7 |& E7 V4 |$ i
#include <STDLIB.H>
( w* q2 x" M# Q( i" o#include <STDIO.H>6 z+ {7 K( }" f
#include <CONIO.H>
. z% x; r4 R# i5 F#include <DOS.H></FONT></P>
6 z( g" V8 b+ s$ E% J, J( M<P><FONT color=#0000ff>#define PIXEL_COUNT 1000 " k7 N! i# W3 \+ M* c( ]
#define DELAY_TIME 100 /* in milliseconds */ </FONT></P>
: e5 N+ g+ [$ K6 Y" G7 Q<P><FONT color=#0000ff>int main(void) 0 J$ d6 P: z( u" y/ r
{
. g; i0 |! \5 M; I( S9 X4 m$ X/* request autodetection */ $ T8 n# \3 G6 J$ }+ o% [- ^# n
int gdriver = DETECT, gmode, errorcode;
$ E& g* d8 E$ t9 u" x( r: uint i, x, y, color, maxx, maxy, maxcolor, seed; </FONT></P>
( b7 T+ m3 E" f" Z<P><FONT color=#0000ff>/* initialize graphics and local variables */
: M+ ^2 \% `5 Minitgraph(&gdriver, &gmode, ""); </FONT></P>
7 |+ q3 [6 k3 ]% r8 [<P><FONT color=#0000ff>/* read result of initialization */ ! _4 R; n s$ i4 d+ H/ v4 D
errorcode = graphresult();
4 g+ {' u( ?, ?& _: iif (errorcode != grOk) /* an error occurred */ # [2 G! m4 X- y$ ~
{ - e$ S. Z; \7 @: Q e7 g
printf("Graphics error: %s\n", grapherrormsg(errorcode));
6 d9 P( @: F% h! h' c- xprintf("Press any key to halt:");
8 s! T" V! n9 P" H7 W* qgetch();
6 x9 S$ H- t- p4 D0 a. fexit(1); /* terminate with an error code */ " q, J8 h( q: [4 c* F; @" i
} </FONT></P>3 @6 q P& ~/ }; K) X. O
<P><FONT color=#0000ff>maxx = getmaxx() + 1; # A7 T1 T. ?' W4 q
maxy = getmaxy() + 1; , G w% E% d. l1 s$ M6 ^" u
maxcolor = getmaxcolor() + 1; </FONT></P>
, B2 N4 |: a- ^: c<P><FONT color=#0000ff>while (!kbhit()) % D& k' D. K/ R# c8 H
{
$ ?. _$ u( P6 ?9 N& e/* seed the random number generator */ : F) K+ z7 v K; R" r: S# \( b
seed = random(32767); " I8 t/ f- U. _/ i8 {
srand(seed); " T8 R* \& f$ M9 d3 }2 p
for (i=0; i<PIXEL_COUNT; <br i++)> { 7 x( @; w# f: `
x = random(maxx); " j1 L- @4 K" V
y = random(maxy); 1 s3 i% L6 u5 d; m/ q
color = random(maxcolor); 6 v" \" o2 W) `0 ~6 L7 K
putpixel(x, y, color);
1 l1 U3 H2 t7 [+ d} </FONT></P>
0 t# c: x5 x# E) C<P><FONT color=#0000ff>delay(DELAY_TIME); 5 E! c) }' D% J
srand(seed); 3 m9 E6 L/ m& C
for (i=0; i<PIXEL_COUNT; <br i++)> {
( M2 v% y6 _; B$ nx = random(maxx); 2 N! e( Q7 y' u! {9 d
y = random(maxy);
5 V ?/ f% q8 L& t, h& P1 Gcolor = random(maxcolor);
& Y9 {4 X9 F( x& yif (color == getpixel(x, y)) ' H' }$ @! d0 ]% W* d% @- ]
putpixel(x, y, 0);
$ Q0 I R- X- R0 Q/ y7 L}
, L7 S5 r- @$ w+ b5 d E} </FONT></P>( ?/ w" ? _+ _) o1 {9 q ]2 h" z
<P><FONT color=#0000ff>/* clean up */ 4 N5 A7 L. {' B1 O4 u3 Q$ L F
getch();
! F# ^+ R* ]7 l+ eclosegraph();
3 w K) U! `' a* M& P0 b; ^3 K4 O7 Qreturn 0;
; E8 u0 y4 V$ p, K5 \" @% I9 m}
0 P/ I% A4 Q% L4 p</FONT>
' \0 M' n0 d- R8 r</P>
" {3 l3 }0 @. O+ o<P><FONT color=#ff0000>函数名: puts </FONT>
) `! u+ j! V, P! j, T& D功 能: 送一字符串到流中
) ]% e" `4 x! { n8 j用 法: int puts(char *string); - X- @( `0 @$ b8 n; y* c" X
程序例: </P>
% x! P1 U9 Z" @; g( D<P><FONT color=#0000ff>#include <STDIO.H>
' i9 S. U( K4 ^# E) k: ? _' gint main(void)
% Q4 [5 W4 ^3 S- w{ $ D9 J# v! [1 c# w, v
char string[] = "This is an example output string\n"; </FONT></P>
* |; l3 A) k1 M) B+ r- C1 \3 U+ g0 W<P><FONT color=#0000ff>puts(string);
- V E2 V' |* v: X& y& ~. r$ ~return 0;
$ H+ \* d# a' x} </FONT>% s6 c' |& z" g e' }
A& h9 Y8 A! s3 x" q</P>/ k7 O3 a( ~, Z, c# z
<P><FONT color=#ff0000>函数名: puttext </FONT>
' ^" X3 f+ z! B H4 T" D4 N; j功 能: 将文本从存储区拷贝到屏幕 5 F) m( a! X P) j9 F6 c
用 法: int puttext(int left, int top, int right, int bottom, void *source); 3 \5 Z& \* q6 A! p5 ^
程序例: </P>" c5 j$ f, Z: W/ e' W/ e* L' w
<P><FONT color=#0000ff>#include <CONIO.H>( T3 E# o. j# w% v% X
int main(void)
4 u& o s) a- r4 V; ^9 |! s{
% r3 H; b2 L) D& M% `. fchar buffer[512]; </FONT></P>8 g; `) e; l. m
<P><FONT color=#0000ff>/* put some text to the console */ 0 o; f7 H3 D- ]9 q3 K
clrscr();
# Y- K% Z$ g( d: E; tgotoxy(20, 12);
/ ]: z" ?+ C' v. `cprintf("This is a test. Press any key to continue ...");
* D& p& ~& a- ]" Z: }9 ngetch(); </FONT></P>4 d X% n+ g. c+ T3 Q1 K* J
<P><FONT color=#0000ff>/* grab screen contents */ # @/ Z% L3 z1 D# }# O& Y$ G
gettext(20, 12, 36, 21,buffer);
% S# ^4 q2 G6 z# s& a7 P$ X Fclrscr(); </FONT></P>
' s9 ~" y# {- V6 S) Y1 P<P><FONT color=#0000ff>/* put selected characters back to the screen */
7 ]+ E+ l5 w# b& f6 agotoxy(20, 12);
% T/ ]# T) W8 C0 wputtext(20, 12, 36, 21, buffer); 0 V' X3 x1 `# H5 u X+ r8 Q! _
getch(); </FONT></P>
. c" r1 K, P% N2 T' J/ H6 ~5 [<P><FONT color=#0000ff>return 0; 1 R' \8 y* G; e3 L- p
} 2 S2 p3 I9 o8 @% x8 i
</FONT>
3 s* F) G4 O1 `/ O% @/ F" w% R. J</P>
1 i. P8 X6 P! J<P><FONT color=#ff0000>函数名: putw </FONT>: Y; \! |1 {0 Q% A9 Z0 `
功 能: 把一字符或字送到流中 * w# Y$ A/ K5 R/ t! k
用 法: int putw(int w, FILE *stream);
6 X' K0 @& Z$ S p6 j3 R! l程序例: </P>5 |8 H0 f7 b9 |9 E3 U
<P><FONT color=#0000ff>#include <STDIO.H>
) g& v: V6 `# x" i6 A( C2 x#include <STDLIB.H></FONT></P>
0 w. y$ i; w' e1 l<P><FONT color=#0000ff>#define FNAME "test.$$$" </FONT></P>
6 s$ F9 _3 T. v$ i" \$ i( X<P><FONT color=#0000ff>int main(void) 4 x% z9 U" O5 ?/ G/ l+ x @( J
{ 3 g' L! X }: \4 N$ W
FILE *fp; 2 V9 [' z/ F& k
int word; </FONT></P>, ?0 y3 g y3 B% e
<P><FONT color=#0000ff>/* place the word in a file */
F2 k. }2 n8 e8 gfp = fopen(FNAME, "wb");
; E8 P8 y4 B& k7 w! Tif (fp == NULL) - p+ Q8 l g1 {3 I
{ 4 y9 m) {6 W9 k% G5 H
printf("Error opening file %s\n", FNAME); . ? I: g0 [+ j s. i- _/ `
exit(1);
3 V; P T, n' F} </FONT></P>8 ]) j; {; g6 I5 Y V5 g
<P><FONT color=#0000ff>word = 94; % V/ X0 g: @; J
putw(word,fp);
' H- X* z, O0 U9 ]4 d: ]0 iif (ferror(fp))
: e, X( b% S+ f6 t* i3 V) yprintf("Error writing to file\n");
0 C" k5 w2 B0 _: B/ |/ B4 C7 Relse
9 \+ I9 t* ^, [5 x, k' [. nprintf("Successful write\n");
2 n& v6 E3 q+ Pfclose(fp); </FONT></P>
( g% x, A+ t5 `4 ^$ g" y7 s( p. u<P><FONT color=#0000ff>/* reopen the file */
+ \4 h/ D/ |/ T- o% hfp = fopen(FNAME, "rb");
; r* M2 m4 |, |- U8 }/ k/ Tif (fp == NULL) - M$ r0 g8 G! k2 r. y) K, Z) u
{
- [1 s3 {6 R: k8 Fprintf("Error opening file %s\n", FNAME);
+ ^, A3 ^9 b& x. lexit(1); ( m5 o9 l {9 v) `9 c
} </FONT></P>* b( A; k3 v+ ?
<P><FONT color=#0000ff>/* extract the word */ ' ^& O6 U5 X4 L3 c
word = getw(fp);
6 A7 I# i0 G& R7 ]# m( Z. u% t D8 |if (ferror(fp))
. g* k* u5 e. ^; _- uprintf("Error reading file\n");
7 T( _, j3 P! ~else 4 d' v; {6 ~& f" ?6 T
printf("Successful read: word = %d\n", word); </FONT></P>$ G% |' x# \9 x _- F& c5 R
<P><FONT color=#0000ff>/* clean up */ : U2 R% U" O5 ]2 M: f. u' N+ w, W
fclose(fp);
3 Z7 I. @' m6 |; I; s3 Bunlink(FNAME); </FONT></P># l/ b2 V8 A$ h6 z( d
<P><FONT color=#0000ff>return 0;
1 r, C* r8 |! L* F9 y0 ]( f} </FONT></P> |
zan
|