📄 fd.htm
字号:
struct DOSERROR info; </p>
<p> fp =
fopen("perror.dat","r"); <br>
if (!fp) perror("Unable to open file
for <br>
reading"); <br>
dosexterr(&info); </p>
<p> printf("Extended DOS error \ <br>
information:\n"); <br>
printf(" Extended error: \ <br>
%d\n",info.exterror); <br>
printf("
Class: \ <br>
%x\n",info.class); <br>
printf("
Action: \ <br>
%x\n",info.action); <br>
printf("
Error Locus: \ <br>
%x\n",info.locus); </p>
<p> return 0; <br>
} <br>
<br>
</p>
<p>函数名: dostounix <br>
功 能: 转换日期和时间为UNIX时间格式 <br>
用 法: long dostounix(struct date *dateptr,
struct time *timeptr); <br>
程序例: </p>
<p> #include <time.h> <br>
#include <stddef.h> <br>
#include <dos.h> <br>
#include <stdio.h> </p>
<p> int main(void) <br>
{ <br>
time_t t; <br>
struct time d_time; <br>
struct date d_date; <br>
struct tm *local; </p>
<p> getdate(&d_date); <br>
gettime(&d_time); </p>
<p> t = dostounix(&d_date,
&d_time); <br>
local = localtime(&t); <br>
printf("Time and Date:
%s\n", \ <br>
asctime(local)); </p>
<p> return 0; <br>
} <br>
<br>
</p>
<p>函数名: drawpoly <br>
功 能: 画多边形 <br>
用 法: void far drawpoly(int numpoints, int far
*polypoints); <br>
程序例: </p>
<p>#include <graphics.h> <br>
#include <stdlib.h> <br>
#include <stdio.h> <br>
#include <conio.h> </p>
<p>int main(void) <br>
{ <br>
/* request auto detection */ <br>
int gdriver = DETECT, gmode, errorcode; <br>
int maxx, maxy; </p>
<p> /* our polygon array */ <br>
int poly[10]; </p>
<p> /* initialize graphics and local <br>
variables */ <br>
initgraph(&gdriver, &gmode,
""); </p>
<p> /* read result of initialization */ <br>
errorcode = graphresult(); <br>
if (errorcode != grOk) <br>
/* an error occurred */ <br>
{ <br>
printf("Graphics
error: %s\n", \ <br>
grapherrormsg(errorcode));
<br>
printf("Press any key
to halt:"); <br>
getch(); <br>
/* terminate with an error code */ <br>
exit(1); <br>
} </p>
<p> maxx = getmaxx(); <br>
maxy = getmaxy(); </p>
<p> poly[0] = 20;
/* 1st vertext */ <br>
poly[1] = maxy / 2; </p>
<p> poly[2] = maxx - 20; /* 2nd */ <br>
poly[3] = 20; </p>
<p> poly[4] = maxx - 50; /* 3rd */ <br>
poly[5] = maxy - 20; </p>
<p> poly[6] = maxx / 2; /* 4th */ <br>
poly[7] = maxy / 2; <br>
/* <br>
drawpoly doesn't automatically close <br>
the polygon, so we close it. <br>
*/ <br>
poly[8] = poly[0]; <br>
poly[9] = poly[1]; </p>
<p> /* draw the polygon */ <br>
drawpoly(5, poly); </p>
<p> /* clean up */ <br>
getch(); <br>
closegraph(); <br>
return 0; <br>
} <br>
<br>
</p>
<p>函数名: dup <br>
功 能: 复制一个文件句柄 <br>
用 法: int dup(int handle); <br>
程序例: </p>
<p>#include <string.h> <br>
#include <stdio.h> <br>
#include <conio.h> <br>
#include <io.h> </p>
<p>void flush(FILE *stream); </p>
<p>int main(void) <br>
{ <br>
FILE *fp; <br>
char msg[] = "This is a test"; </p>
<p> /* create a file */ <br>
fp = fopen("DUMMY.FIL",
"w"); </p>
<p> /* write some data to the file */ <br>
fwrite(msg, strlen(msg), 1, fp); </p>
<p> clrscr(); <br>
printf("Press any key to flush \ <br>
DUMMY.FIL:"); <br>
getch(); </p>
<p> /* flush the data to DUMMY.FIL without <br>
closing it */ <br>
flush(fp); </p>
<p> printf("\nFile was flushed, Press
any \ <br>
key to quit:"); <br>
getch(); <br>
return 0; <br>
} </p>
<p>void flush(FILE *stream) <br>
{ <br>
int duphandle; </p>
<p> /* flush TC's internal buffer */ <br>
fflush(stream); </p>
<p> /* make a duplicate file handle */ <br>
duphandle = dup(fileno(stream)); </p>
<p> /* close the duplicate handle to flush
the <br>
DOS buffer */ <br>
close(duphandle); <br>
} <br>
<br>
</p>
<p>函数名: dup2 <br>
功 能: 复制文件句柄 <br>
用 法: int dup2(int oldhandle, int newhandle); <br>
程序例: </p>
<p>#include <sys\stat.h> <br>
#include <string.h> <br>
#include <fcntl.h> <br>
#include <io.h> </p>
<p>int main(void) <br>
{ <br>
#define STDOUT 1 </p>
<p> int nul, oldstdout; <br>
char msg[] = "This is a test"; </p>
<p> /* create a file */ <br>
nul = open("DUMMY.FIL", O_CREAT |
O_RDWR, <br>
S_IREAD | S_IWRITE); </p>
<p> /* create a duplicate handle for standard
<br>
output */ <br>
oldstdout = dup(STDOUT); <br>
/* <br>
redirect standard output
to DUMMY.FIL <br>
by duplicating the file
handle onto the <br>
file handle for standard
output. <br>
*/ <br>
dup2(nul, STDOUT); </p>
<p> /* close the handle for DUMMY.FIL */ <br>
close(nul); </p>
<p> /* will be redirected into DUMMY.FIL */ <br>
write(STDOUT, msg, strlen(msg)); </p>
<p> /* restore original standard output <br>
handle */ <br>
dup2(oldstdout, STDOUT); </p>
<p> /* close duplicate handle for STDOUT */ <br>
close(oldstdout); </p>
<p> return 0; <br>
} <br>
</p>
</td>
</tr>
</table>
</center></div><div align="center"><center>
<table border="0" cellspacing="1" width="640">
<tr>
<td class="p9" height="60"> <script>document.write("<p><a href=\"http://view.gznet.com/cgi-bin/rl_views.cgi?UID=10013421\" target=sxrl>");
document.write("<img src=\"http://refer.gznet.com/cgi-bin/rl_refer2.cgi?UID=10013421&refer="+escape(top.document.referrer)+"\" width=1 height=1 border=0 alt=\" \">");
document.write("</a>");
</script></td>
</tr>
</table>
</center></div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -