内财数模协会
发表于 2004-5-8 17:25:42
<P>函数名: difftime
功能: 计算两个时刻之间的时间差
用法: double difftime(time_t time2, time_t time1);
程序例: <P>#include <time.h>
#include <stdio.h>
#include <dos.h>
#include <conio.h> <P>int main(void)
{
time_t first, second; <P> clrscr();
first = time(NULL);/* Gets system
time */
delay(2000); /* Waits 2 secs */
second = time(NULL); /* Gets system time
again */ <P> printf("The difference is: %f \
seconds\n",difftime(second,first));
getch(); <P> return 0;
}
</P>
内财数模协会
发表于 2004-5-8 17:25:53
<P>函数名: disable
功能: 屏蔽中断
用法: void disable(void);
程序例: <P>/***NOTE: This is an interrupt service
routine. You cannot compile this program
with Test Stack Overflow turned on and
get an executable file that operates
correctly. */ <P>#include <stdio.h>
#include <dos.h>
#include <conio.h> <P>#define INTR 0X1C /* The clock tick
interrupt */ <P>void interrupt ( *oldhandler)(void); <P>int count=0; <P>void interrupt handler(void)
{
/* disable interrupts during the handling of
the interrupt */
disable();
/* increase the global counter */
count++;
/* reenable interrupts at the end of the
handler */
enable();
/* call the old routine */
oldhandler();
} <P>int main(void)
{
/* save the old interrupt vector */
oldhandler = getvect(INTR); <P>/* install the new interrupt handler */
setvect(INTR, handler); <P>/* loop until the counter exceeds 20 */
while (count < 20)
printf("count is %d\n",count); <P>/* reset the old interrupt handler */
setvect(INTR, oldhandler); <P> return 0;
} </P>
内财数模协会
发表于 2004-5-8 17:26:02
<P>函数名: div
功能: 将两个整数相除, 返回商和余数
用法: div_t (int number, int denom);
程序例: <P>#include <stdlib.h>
#include <stdio.h> <P>div_t x; <P>int main(void)
{
x = div(10,3);
printf("10 div 3 = %d remainder %d\n", x.quot, x.rem); <P> return 0;
}
</P>
内财数模协会
发表于 2004-5-8 17:26:12
<P>函数名: dosexterr
功能: 获取扩展DOS错误信息
用法: int dosexterr(struct DOSERR *dblkp);
程序例: <P>#include <stdio.h>
#include <dos.h> <P>int main(void)
{
FILE *fp;
struct DOSERROR info; <P> fp = fopen("perror.dat","r");
if (!fp) perror("Unable to open file for
reading");
dosexterr(&info); <P> printf("Extended DOS error \
information:\n");
printf(" Extended error: \
%d\n",info.exterror);
printf(" Class: \
%x\n",info.class);
printf(" Action: \
%x\n",info.action);
printf(" Error Locus: \
%x\n",info.locus); <P> return 0;
}
</P>
内财数模协会
发表于 2004-5-8 17:26:22
<P>函数名: dostounix
功能: 转换日期和时间为UNIX时间格式
用法: long dostounix(struct date *dateptr, struct time *timeptr);
程序例: <P> #include <time.h>
#include <stddef.h>
#include <dos.h>
#include <stdio.h> <P> int main(void)
{
time_t t;
struct time d_time;
struct date d_date;
struct tm *local; <P> getdate(&d_date);
gettime(&d_time); <P> t = dostounix(&d_date, &d_time);
local = localtime(&t);
printf("Time and Date: %s\n", \
asctime(local)); <P> return 0;
}
</P>
内财数模协会
发表于 2004-5-8 17:26:34
<P>函数名: drawpoly
功能: 画多边形
用法: void far drawpoly(int numpoints, int far *polypoints);
程序例: <P>#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h> <P>int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int maxx, maxy; <P> /* our polygon array */
int poly; <P> /* initialize graphics and local
variables */
initgraph(&gdriver, &gmode, ""); <P> /* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk)
/* an error occurred */
{
printf("Graphics error: %s\n", \
grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
/* terminate with an error code */
exit(1);
} <P> maxx = getmaxx();
maxy = getmaxy(); <P> poly = 20; /* 1st vertext */
poly = maxy / 2; <P> poly = maxx - 20; /* 2nd */
poly = 20; <P> poly = maxx - 50; /* 3rd */
poly = maxy - 20; <P> poly = maxx / 2;/* 4th */
poly = maxy / 2;
/*
drawpoly doesn't automatically close
the polygon, so we close it.
*/
poly = poly;
poly = poly; <P> /* draw the polygon */
drawpoly(5, poly); <P> /* clean up */
getch();
closegraph();
return 0;
}
</P>
内财数模协会
发表于 2004-5-8 17:26:46
<P>函数名: dup
功能: 复制一个文件句柄
用法: int dup(int handle);
程序例: <P>#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <io.h> <P>void flush(FILE *stream); <P>int main(void)
{
FILE *fp;
char msg[] = "This is a test"; <P> /* create a file */
fp = fopen("DUMMY.FIL", "w"); <P> /* write some data to the file */
fwrite(msg, strlen(msg), 1, fp); <P> clrscr();
printf("Press any key to flush \
DUMMY.FIL:");
getch(); <P> /* flush the data to DUMMY.FIL without
closing it */
flush(fp); <P> printf("\nFile was flushed, Press any \
key to quit:");
getch();
return 0;
} <P>void flush(FILE *stream)
{
int duphandle; <P> /* flush TC's internal buffer */
fflush(stream); <P> /* make a duplicate file handle */
duphandle = dup(fileno(stream)); <P> /* close the duplicate handle to flush the
DOS buffer */
close(duphandle);
}
</P>
内财数模协会
发表于 2004-5-8 17:26:57
<P>函数名: dup2
功能: 复制文件句柄
用法: int dup2(int oldhandle, int newhandle);
程序例: <P>#include <sys\stat.h>
#include <string.h>
#include <fcntl.h>
#include <io.h> <P>int main(void)
{
#define STDOUT 1 <P> int nul, oldstdout;
char msg[] = "This is a test"; <P> /* create a file */
nul = open("DUMMY.FIL", O_CREAT | O_RDWR,
S_IREAD | S_IWRITE); <P> /* create a duplicate handle for standard
output */
oldstdout = dup(STDOUT);
/*
redirect standard output to DUMMY.FIL
by duplicating the file handle onto the
file handle for standard output.
*/
dup2(nul, STDOUT); <P> /* close the handle for DUMMY.FIL */
close(nul); <P> /* will be redirected into DUMMY.FIL */
write(STDOUT, msg, strlen(msg)); <P> /* restore original standard output
handle */
dup2(oldstdout, STDOUT); <P> /* close duplicate handle for STDOUT */
close(oldstdout); <P> return 0;
}
</P>
内财数模协会
发表于 2004-5-8 17:29:18
函数名: ecvt
功能: 把一个浮点数转换为字符串
用法: char ecvt(double value, int ndigit, int *decpt, int *sign);
程序例: <P>#include <stdlib.h>
#include <stdio.h>
#include <conio.h> <P>int main(void)
{
char *string;
double value;
int dec, sign;
int ndig = 10; <P> clrscr();
value = 9.876;
string = ecvt(value, ndig, &dec, &sign);
printf("string = %s dec = %d \
sign = %d\n", string, dec, sign); <P> value = -123.45;
ndig= 15;
string = ecvt(value,ndig,&dec,&sign);
printf("string = %s dec = %d sign = %d\n",
string, dec, sign);
<P> value = 0.6789e5; /* scientific
notation */
ndig = 5;
string = ecvt(value,ndig,&dec,&sign);
printf("string = %s dec = %d\
sign = %d\n", string, dec, sign); <P> return 0;
}
</P>
内财数模协会
发表于 2004-5-8 17:29:27
<P>函数名: ellipse
功能: 画一椭圆
用法: void far ellipse(int x, int y, int stangle, int endangle,
int xradius, int yradius);
程序例: <P>#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h> <P>int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int midx, midy;
int stangle = 0, endangle = 360;
int xradius = 100, yradius = 50; <P> /* initialize graphics, local variables */
initgraph(&gdriver, &gmode, ""); <P> /* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk)
/* an error occurred */
{
printf("Graphics error: %s\n",
grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
/* terminate with an error code */
} <P> midx = getmaxx() / 2;
midy = getmaxy() / 2;
setcolor(getmaxcolor()); <P> /* draw ellipse */
ellipse(midx, midy, stangle, endangle,
xradius, yradius); <P> /* clean up */
getch();
closegraph();
return 0;
}
</P>