- 在线时间
- 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>函数大全(d开头)</FONT></B></FONT>
2 F# }& m3 a* c+ [" F</P>$ P9 D& U( I. p
<p>< ><FONT color=#ff0000>函数名: delay </FONT>% r# s6 ^: E/ A* | {
功 能: 将程序的执行暂停一段时间(毫秒) 7 o+ \! a/ v* l) W: j
用 法: void delay(unsigned milliseconds); ' j- I' d& b( Z
程序例:
" x, y" B% E5 k9 H. U<FONT color=#0000ff>/* Emits a 440-Hz tone for 500 milliseconds */ ' M: U% K0 n( a% ~ c
#include <DOS.H></FONT></P>< ><FONT color=#0000ff>int main(void)
) i9 E$ y1 y& K5 H! I; ^{
0 S: U$ m4 W/ @3 c; o/ N0 W. qsound(440);
$ [; b, f" Y5 G6 ?, I! K1 bdelay(500);
) T0 C! T& \$ I9 inosound(); </FONT></P>< ><FONT color=#0000ff>return 0;
: u' d% ]1 F) n0 r3 g' ?* P, ~8 J}
/ F" L: K, o4 j, o! J
4 v7 W' l) I. O/ g2 C( b</FONT></P>< ><FONT color=#ff0000>函数名: delline </FONT>' F6 b8 [. ?2 m6 i
功 能: 在文本窗口中删去一行 ) c2 ], [! t0 y. C m
用 法: void delline(void); 8 {: ~- i, p3 q5 {* }0 m
程序例: </P>< ><FONT color=#0000ff>#include <CONIO.H></FONT></P>< ><FONT color=#0000ff>int main(void) : Y- m% u9 G+ p6 r A
{ $ A' J) A$ I N' V, h; Q% U
clrscr(); ! V; Z4 z# |) O- u6 \( k
cprintf("The function DELLINE deletes \ 2 i; i8 t4 {: z/ ?0 f
the line containing the\r\n"); 7 |4 G) y4 ~$ c
cprintf("cursor and moves all lines \ - Z# [, v( O; }5 O' Z5 x
below it one line up.\r\n"); / \6 z* G$ {( V7 v' D" {
cprintf("DELLINE operates within the \
' z" s; k, K% R* ]+ g. q- pcurrently active text\r\n");
* I! B* @- i# z9 T8 j0 E8 ]cprintf("window. Press any key to \
9 M( a( G) r5 g2 acontinue . . .");
& R0 K4 `3 V0 ggotoxy(1,2); /* Move the cursor to the
4 Q1 ] d6 ~$ K( ]& D& `second line and first column */ , Y0 Q' N; J8 T+ A0 [, \
getch(); </FONT></P>< ><FONT color=#0000ff>delline();
, r0 S' @* q* z4 p8 X( Agetch(); </FONT></P>< ><FONT color=#0000ff>return 0; 5 o4 v& K7 V o1 N b
} </FONT>6 b" J. ]/ o: M* b) I& k, `
</P>< ><FONT color=#ff0000>函数名: detectgraph </FONT>
- d5 R/ Z# y3 ^+ a0 q& n' Y5 Y功 能: 通过检测硬件确定图形驱动程序和模式
* O! O$ B) F- Z. g用 法: void far detectgraph(int far *graphdriver, int far *graphmode); 5 i" a/ J' n9 [5 m* s
程序例: </P>< ><FONT color=#0000ff>#include <GRAPHICS.H>: L; i8 }' k; Q7 c: B- O9 S2 ^
#include <STDLIB.H>
. M* b' [2 V, B ^% p6 b$ U/ C#include <STDIO.H>
$ I2 q: [1 Y- |+ F4 i#include <CONIO.H></FONT></P>< ><FONT color=#0000ff>/* names of the various cards supported */
- c2 y& L& ]; V+ j1 J& J& e: fchar *dname[] = { "requests detection", ( x9 T4 M- w- C% L* ^7 z
"a CGA", 7 o, I9 O* C" e+ b1 Z% E
"an MCGA", # M+ K4 J$ e, ^/ E
"an EGA", : J; r+ [% K0 A! m
"a 64K EGA",
2 R6 B3 e; j9 A# `"a monochrome EGA", 8 c# ^6 S, f3 o4 S8 F. X# x/ x2 G' s
"an IBM 8514", , X* \. Q- H1 \+ \: v g
"a Hercules monochrome", ' K- E' l8 |: h. p% }) T
"an AT&T 6300 PC", - r o+ P& h6 a: J7 g# G1 H
"a VGA", * `! b: L2 y1 }. ~3 k
"an IBM 3270 PC" ) ~2 ^6 ^" o; @. R9 w$ e# [
}; </FONT></P>< ><FONT color=#0000ff>int main(void) - H" u0 Q0 Y9 [
{ # P* U# ]! b+ |2 W+ I
/* returns detected hardware info. */ $ ~/ K4 D4 b& t8 z/ p
int gdriver, gmode, errorcode; </FONT></P>< ><FONT color=#0000ff>/* detect graphics hardware available */ # u7 I- q% _7 p
detectgraph(&gdriver, &gmode); </FONT></P>< ><FONT color=#0000ff>/* read result of detectgraph call */ # @& m" v A, V2 t1 F1 `
errorcode = graphresult();
: l8 U: u4 ~+ ^8 O1 nif (errorcode != grOk) /* an error
3 }5 m4 Y4 `3 r# x8 t- e: Zoccurred */
$ E* Y3 Q8 V1 U' I( Y{
% e; J2 f9 Q6 O) V; kprintf("Graphics error: %s\n", \
: R- e8 O$ \3 u5 r% S& S6 tgrapherrormsg(errorcode));
; z# K; ^ t& |' e" ?2 Q. z, tprintf(" ress any key to halt:");
& e! i# e6 f8 A/ q# J" j/ E$ Tgetch(); / c# ]' d! _8 f8 |1 U+ E# t: ?
exit(1); /* terminate with an error 2 X$ ]. i+ z* T; M3 K
code */
8 S$ v$ [; `6 e# e} </FONT></P>< ><FONT color=#0000ff>/* display the information detected */
1 h3 r8 n9 C# a& Kclrscr();
% m8 s' y9 ?7 u9 [, \: hprintf("You have %s video display \ 7 `1 w. ?; U& n2 ?& }
card.\n", dname[gdriver]); 4 D8 X3 Z% b! t
printf(" ress any key to halt:"); 8 n6 H3 [. j4 o7 N% h
getch();
G% r. |- _4 p2 `! n. Sreturn 0; & l3 G+ t7 p+ g& q! G; d
} </FONT>
" s( w0 `8 k# G3 r. V
; O: U, C$ v' A. q( h% u4 {; C/ p9 \" Z, {0 E& |# ^$ W4 I$ W
</P>< ><FONT color=#ff0000>函数名: difftime </FONT>) |1 @' o O q
功 能: 计算两个时刻之间的时间差
; U$ D" H Q1 e) h z# K j7 j/ E用 法: double difftime(time_t time2, time_t time1);
6 a2 W: q2 D' a6 H9 F程序例: </P>< ><FONT color=#0000ff>#include <TIME.H>: K0 l0 t) a8 x3 w- Y& n+ g
#include <STDIO.H>
. R- q" {5 r; |3 \7 Q9 `#include <DOS.H># y" p- | C& p2 \) C
#include <CONIO.H></FONT></P>< ><FONT color=#0000ff>int main(void)
5 Y" u e! j" \ s: L# e0 T b! S% g{
* S' ?9 \) [3 Y! {2 |7 vtime_t first, second; </FONT></P>< ><FONT color=#0000ff>clrscr();
1 |1 e+ z: q. V7 d; zfirst = time(NULL); /* Gets system
! p& w6 C% }9 `3 c, y7 Rtime */
' c2 n6 z: k1 H) u" w3 @: @delay(2000); /* Waits 2 secs */ ; |$ I4 j; f4 P' e1 K; O, u
second = time(NULL); /* Gets system time w% i3 A4 `& j9 l
again */ </FONT></P>< ><FONT color=#0000ff>printf("The difference is: %f \
* Z; N* }" _1 V- zseconds\n",difftime(second,first));
8 g0 `2 Y/ o) ?7 kgetch(); </FONT></P>< ><FONT color=#0000ff>return 0; , h( T* b- b% x$ v, @
}
9 D2 i6 M$ Q7 G2 l& ]2 h</FONT>
0 N- o- z' z* i7 h3 W8 ?</P>< ><FONT color=#ff0000>函数名: disable </FONT>, b. H! S: X% [5 t3 l' r' W) _1 _
功 能: 屏蔽中断 # {6 v) L5 a5 v3 S: B/ `
用 法: void disable(void); 6 F* T! }2 o3 r, p) c4 a% M
程序例: </P>< ><FONT color=#0000ff>/***NOTE: This is an interrupt service
G: ? U$ C4 f7 v/ Hroutine. You cannot compile this program
+ s) B% x9 a3 d9 Q% lwith Test Stack Overflow turned on and 7 _. G" t' k7 \; t
get an executable file that operates
5 Y3 ]% V- i# e' q# a2 A7 e: ?correctly. */ </FONT></P>< ><FONT color=#0000ff>#include <STDIO.H>$ D9 J- N/ k* Z5 i
#include <DOS.H>
. `: S) E/ u: W0 G5 L4 r' v#include <CONIO.H></FONT></P>< ><FONT color=#0000ff>#define INTR 0X1C /* The clock tick
& S$ X" w9 p: v3 S+ M. C# o% Finterrupt */ </FONT></P>< ><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>< ><FONT color=#0000ff>int count=0; </FONT></P><P><FONT color=#0000ff>void interrupt handler(void) & P' s4 J( J! G; a& {! r
{
$ _* S( b9 v+ F/* disable interrupts during the handling of
9 e, }# b1 y1 d0 Z Z1 ^the interrupt */
* Z3 w+ ]) L9 w7 v! J& z& @disable();
7 H& K8 K/ H u, |0 g2 p/* increase the global counter */
" E$ v. p/ Z: O1 e1 gcount++; 1 p. m& T% v. N# G8 _& Z, K
/* reenable interrupts at the end of the 0 ?) T) ~% \6 ~2 L. o8 R. L
handler */ $ |$ g5 Y9 L; a0 C$ @5 z/ ?
enable(); , k5 Y" E2 h' i) [8 ?
/* call the old routine */
2 U/ Q8 q! k. X6 P8 foldhandler(); 5 t) s! h3 I: e9 V z: {
} </FONT></P><P><FONT color=#0000ff>int main(void)
2 K, v: M2 E7 b$ ^& G+ }{
- c7 e3 B2 e+ W/* save the old interrupt vector */ ' S% }# `$ r: }8 C- `1 h
oldhandler = getvect(INTR); </FONT></P><P><FONT color=#0000ff>/* install the new interrupt handler */
1 A; L. Z* ]& B m% ]. o9 Tsetvect(INTR, handler); </FONT></P><P><FONT color=#0000ff>/* loop until the counter exceeds 20 */ , m# s8 e l& v
while (count < 20) ; o) k* `8 `* W8 t
printf("count is %d\n",count); </FONT></P><P><FONT color=#0000ff>/* reset the old interrupt handler */ 7 b5 S" [" u% ^/ j( s Z
setvect(INTR, oldhandler); </FONT></P><P><FONT color=#0000ff>return 0;
* a6 N: M+ C J& n: R; O: F} </FONT></P><P><FONT color=#ff0000>函数名: div </FONT>
. t# \9 y) _" \+ w功 能: 将两个整数相除, 返回商和余数
; p" d" E$ M9 s. P/ g( A$ G, [3 D用 法: div_t (int number, int denom); . o! t6 |8 F6 w3 H
程序例: </P><P>#<FONT color=#0000ff>include <STDLIB.H>
. P- N8 b+ J) w6 R" v#include <STDIO.H></FONT></P><P><FONT color=#0000ff>div_t x; </FONT></P><P><FONT color=#0000ff>int main(void) ! x/ I/ t. r' L. \9 \' e
{ ) i# T: [2 T& j1 n; C. ^; w
x = div(10,3);
1 v7 P* ~8 ^# X0 N1 S& {printf("10 div 3 = %d remainder %d\n", x.quot, x.rem); </FONT></P><P><FONT color=#0000ff>return 0; ) U, U* t+ y8 g4 M
} " z, S7 p: z* ^
</FONT>/ l) f E3 T8 O4 H( z5 Z) }. I
</P><P><FONT color=#ff0000>函数名: dosexterr </FONT>
) x7 g6 n) }8 }, u9 @% q6 i功 能: 获取扩展DOS错误信息 # D" |: m. U: T: L2 A2 M
用 法: int dosexterr(struct DOSERR *dblkp); ! \. a7 @0 }0 F
程序例: </P><P><FONT color=#0000ff>#include <STDIO.H>
% E3 p7 m' y b#include <DOS.H></FONT></P><P><FONT color=#0000ff>int main(void)
: a9 Q9 y, s2 b# F* c. y{
7 e- n& y' z7 G- t) r! kFILE *fp; & I, b- {5 g) h! d5 i1 p& k
struct DOSERROR info; </FONT></P><P><FONT color=#0000ff>fp = fopen("perror.dat","r"); 3 }5 e" f: a# k8 s
if (!fp) perror("Unable to open file for ; c3 L2 i9 Y; m. K1 k& U. i
reading"); # U. x( [ v* \, T' `
dosexterr(&info); </FONT></P><P><FONT color=#0000ff>printf("Extended DOS error \ . Q& C8 g4 S% P3 Q9 j
information:\n"); ) N' n; b" Q6 {9 l! Y
printf(" Extended error: \
( ?9 d2 {4 S: v0 v. n%d\n",info.exterror); 9 \0 t8 K9 r/ D% q, L
printf(" Class: \ ! v- V7 ~2 n3 v- m5 A8 `% R
%x\n",info.class);
, e, n. H* W) l* X# L7 \3 sprintf(" Action: \
6 I( f2 L. D) I8 H1 H, T. Z4 Q%x\n",info.action); " ^& U7 q% y$ v. @4 N" ^
printf(" Error Locus: \ - |- `7 ~' _$ R: g$ i' R
%x\n",info.locus); </FONT></P><P><FONT color=#0000ff>return 0; ( z0 b0 L4 Z% t
} </FONT>$ g; j2 s s$ B" _" D
! C" J& c3 e- Z* ^) j0 S+ C
</P><P><FONT color=#ff0000>函数名: dostounix </FONT>
' {7 H( j" ?) ~7 l功 能: 转换日期和时间为UNIX时间格式
: k# d4 j8 g) ~; ^用 法: long dostounix(struct date *dateptr, struct time *timeptr); $ Q2 R E: v& i" [
程序例: </P><P><FONT color=#0000ff>#include <TIME.H>; Z$ V* G. Y9 j/ T- m
#include <STDDEF.H>
' ~: O4 B7 l3 `: v1 M+ c* q$ T#include <DOS.H>
0 r% W9 M q1 g- i+ \- ?8 s1 E# u+ z/ a#include <STDIO.H></FONT></P><P><FONT color=#0000ff>int main(void) c9 ~) X0 Q, J5 M
{
+ P3 N3 q! c' F0 p0 ]time_t t; ' @5 f% R& f' Y( [
struct time d_time; : H/ _/ e: a# a" H5 u* @
struct date d_date;
* J# Q& r$ H* ~6 G5 f: Zstruct tm *local; </FONT></P><P><FONT color=#0000ff>getdate(&d_date);
" J7 Y9 w, G8 {. ^/ P6 i: igettime(&d_time); </FONT></P><P><FONT color=#0000ff>t = dostounix(&d_date, &d_time);
# q; e0 y0 O Z, ]local = localtime(&t); J+ t; ~3 M: d
printf("Time and Date: %s\n", \ / r6 ?" w/ s [8 t
asctime(local)); </FONT></P><P><FONT color=#0000ff>return 0;
2 G) O9 |6 E! X5 v0 k} </FONT>3 Y3 H3 a0 ?% P- t3 W/ F
+ o( L+ j/ t# g! L* w) N, g4 [
</P><P><FONT color=#ff0000>函数名: drawpoly </FONT>7 q7 M$ s1 O7 z. ^
功 能: 画多边形 & [- o5 Y/ w2 J
用 法: void far drawpoly(int numpoints, int far *polypoints);
. R( b: ]1 \# r% {程序例: </P><P><FONT color=#0000ff>#include <GRAPHICS.H>
/ Y" _8 {. j& D7 \#include <STDLIB.H>
. f8 b# u3 w* L7 C# M" \#include <STDIO.H>4 G o5 z, e3 s: B# ?. a9 v+ d6 U
#include <CONIO.H></FONT></P><P><FONT color=#0000ff>int main(void)
! x! _4 `4 x- t8 I{
+ V" L& u8 v+ O; ?, v7 t3 f0 k% C/* request auto detection */ % y1 k( L1 [( @, n: l. M
int gdriver = DETECT, gmode, errorcode; 4 _( y j( N1 J. ]
int maxx, maxy; </FONT></P><P><FONT color=#0000ff>/* our polygon array */ 6 H5 }. N I( y, Q0 F
int poly[10]; </FONT></P><P><FONT color=#0000ff>/* initialize graphics and local
* E6 o- d: z O8 X5 bvariables */
" H1 M, L. v. D0 M, Iinitgraph(&gdriver, &gmode, ""); </FONT></P><P><FONT color=#0000ff>/* read result of initialization */ ! F$ _! X) R- _1 m/ D; c
errorcode = graphresult(); ; G% `% _ s+ e! f. ^( W# X
if (errorcode != grOk)
3 b( I* l/ G8 H1 d/* an error occurred */
0 Y) t) t4 Z6 t+ W, n+ j( t( ]{ " c; \4 K6 l/ w, M
printf("Graphics error: %s\n", \ 2 s- H) q. j! s
grapherrormsg(errorcode)); 2 E1 k' ~! H. K% F3 I
printf("Press any key to halt:"); 2 W& ]$ y6 T9 d; n& L
getch(); ; [( X+ v7 J. Z' j# y5 u4 C! X
/* terminate with an error code */ & s9 s9 ^6 @- K/ }: z9 Y
exit(1); 9 w4 D& A: z! [3 W& N
} </FONT></P><P><FONT color=#0000ff>maxx = getmaxx();
( A- [9 J$ g) B( K: wmaxy = getmaxy(); </FONT></P><P><FONT color=#0000ff>poly[0] = 20; /* 1st vertext */ _8 @! C( E0 S ~- ^: T
poly[1] = maxy / 2; </FONT></P><P><FONT color=#0000ff>poly[2] = maxx - 20; /* 2nd */
/ p6 C; S9 z1 x8 npoly[3] = 20; </FONT></P><P><FONT color=#0000ff>poly[4] = maxx - 50; /* 3rd */
6 z8 r# ~7 i4 M. Q7 U, U! Epoly[5] = maxy - 20; </FONT></P><P><FONT color=#0000ff>poly[6] = maxx / 2; /* 4th */
/ t2 `1 S" }5 T* d ?poly[7] = maxy / 2; $ o+ `* A4 g1 t4 F9 _2 e
/*
8 _3 y4 w( d1 I8 z' N/ Adrawpoly doesn't automatically close
w, P0 q! H4 ?5 f2 z+ g k" b2 r! Ithe polygon, so we close it. : n+ |# f" N2 @8 N( b: T
*/
/ O! Z- {- {3 Z2 V( d2 e- Dpoly[8] = poly[0]; . W8 f" D: e% L" L# a1 h8 }
poly[9] = poly[1]; </FONT></P><P><FONT color=#0000ff>/* draw the polygon */
1 m) V3 M2 V. Q4 [. f3 mdrawpoly(5, poly); </FONT></P><P><FONT color=#0000ff>/* clean up */ 0 O; q6 Y$ S1 a. B
getch();
C9 n- I3 N, z4 N" k" iclosegraph(); # X& y w# t; |& s2 M) K- {/ w
return 0; 4 `4 V' @. a1 A! g& l5 s) w) L* b# u9 }
} 1 g% C5 y5 Q( J. }, e0 R7 l
</FONT>
/ |" G9 m5 S2 h* [' r+ e</P><P><FONT color=#ff0000>函数名: dup </FONT>
: h. l( _# A# x+ I. U功 能: 复制一个文件句柄
( O& ]3 u- [8 I4 w3 {6 q3 |用 法: int dup(int handle);
# Z( v4 _+ g/ u5 c程序例: </P><P><FONT color=#0000ff>#include <STRING.H>
7 Z; e3 Y$ Q& {% a9 j#include <STDIO.H>
+ f3 U: E. G0 e4 t#include <CONIO.H>
' p9 o0 Q& D' G: Z#include <IO.H></FONT></P><P><FONT color=#0000ff>void flush(FILE *stream); </FONT></P><P><FONT color=#0000ff>int main(void)
$ p2 }3 z9 \1 |8 s8 k# h{
2 `/ ? p( n6 F, L$ N1 o- |4 d0 TFILE *fp;
; {4 v; f! y) H6 m9 [5 T* mchar msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */ 7 Y/ a. |9 s! R
fp = fopen("DUMMY.FIL", "w"); </FONT></P><P><FONT color=#0000ff>/* write some data to the file */ 2 ~6 d2 @. q; e
fwrite(msg, strlen(msg), 1, fp); </FONT></P><P><FONT color=#0000ff>clrscr(); 1 S, {/ z, t' A. w& l
printf("Press any key to flush \ ) r. l. q8 |, h G" j
DUMMY.FIL:");
3 g* C( ~3 _3 R+ o/ x4 Z" d# i8 Rgetch(); </FONT></P><P><FONT color=#0000ff>/* flush the data to DUMMY.FIL without
6 \( A& p2 e" M: m/ T: Q, Hclosing it */
[4 @0 f0 V& ]: k% @/ k0 u/ `flush(fp); </FONT></P><P><FONT color=#0000ff>printf("\nFile was flushed, Press any \ ! H6 u/ }4 s, w! T$ H
key to quit:");
, b; D7 l8 B+ E1 g# M1 _' F7 Bgetch();
1 _5 }+ `/ S1 H4 n ]' K7 q, Vreturn 0;
5 \, r2 a$ s. [+ b9 C( q" P1 Y} </FONT></P><P><FONT color=#0000ff>void flush(FILE *stream)
( t! ^3 j6 J. j9 o2 f% m{ ) O' G9 A+ R$ h8 a' W: f
int duphandle; </FONT></P><P><FONT color=#0000ff>/* flush TC's internal buffer */ 3 `9 g& _5 k" n% E
fflush(stream); </FONT></P><P><FONT color=#0000ff>/* make a duplicate file handle */
* `) ~1 n* `9 e* A* X4 \: Oduphandle = dup(fileno(stream)); </FONT></P><P><FONT color=#0000ff>/* close the duplicate handle to flush the " O$ _1 f) a: C- L- n
DOS buffer */ ; S/ v- ?* r' E. l- W, w
close(duphandle); 7 ]' T; u6 f) O
}
' `( ]7 T3 }+ Y- x( o0 O7 ]6 R% V; m
[$ y$ }) v7 V- |8 B$ |/ N, n</FONT></P><P><FONT color=#ff0000>函数名: dup2 </FONT>
3 T0 T3 Z% k! n z2 V功 能: 复制文件句柄 6 @3 J9 A$ S9 M2 U9 y! O* q
用 法: int dup2(int oldhandle, int newhandle);
, E/ m4 }: r# {: f程序例: </P><P><FONT color=#0000ff>#include <SYS\STAT.H>. ~8 p# R9 U6 h$ x6 ]4 F4 p
#include <STRING.H>' a. ^0 k0 d- q0 C- ?. @7 r
#include <FCNTL.H>
7 i4 X; O: |% I#include <IO.H></FONT></P><P><FONT color=#0000ff>int main(void)
/ G3 V: B2 q" z% T5 t e8 g{ 4 p8 w% a0 M# O8 d
#define STDOUT 1 </FONT></P><P><FONT color=#0000ff>int nul, oldstdout;
. ^; ?. x9 P3 r+ U3 l! S3 schar msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */
( ^( H, V6 n3 g* }$ e" G/ knul = open("DUMMY.FIL", O_CREAT | O_RDWR, # ]# ~+ j5 c c; t* \. `# y
S_IREAD | S_IWRITE); </FONT></P><P><FONT color=#0000ff>/* create a duplicate handle for standard $ v" _6 K# x, B1 F( L, C! l. j
output */
A% v1 X) B1 J B, N# Q, Koldstdout = dup(STDOUT); : e. I& {) \4 W2 k& \2 y
/*
: v% H! M$ ^5 ?1 Z1 Iredirect standard output to DUMMY.FIL
# o" P/ L! j2 J2 k' ]3 bby duplicating the file handle onto the
% B2 Y B0 M- P F. s- Q, _; i. Cfile handle for standard output.
) v+ ]3 I8 B- V*/
. N4 U" a/ M' m, @$ J7 U- Ydup2(nul, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close the handle for DUMMY.FIL */ $ v) E* ?. d. G# z5 R# x* |' Z
close(nul); </FONT></P><P><FONT color=#0000ff>/* will be redirected into DUMMY.FIL */
1 h# }, Q2 _3 y8 M D/ X) Gwrite(STDOUT, msg, strlen(msg)); </FONT></P><P><FONT color=#0000ff>/* restore original standard output
+ ]) [, G4 x6 E7 `' B1 mhandle */
" p0 i. y. F) ^1 c) ^dup2(oldstdout, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close duplicate handle for STDOUT */ 0 L) @+ K8 }" z6 L! P
close(oldstdout); </FONT></P><P><FONT color=#0000ff>return 0; 9 j _# X0 \* Y8 t
}
/ Q/ H9 x7 H% U; ~( [</FONT></P> |
|