⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cexam.mdb

📁 软件的绝大部分函数的使用说明例子
💻 MDB
📖 第 1 页 / 共 2 页
字号:
==========
access

filename指向被访问的文件名,mode决定access()函数去做什么,它的合法值为:
0 检查文件是否存在
1 检查文件是否可运行
2 检查文件是否可以定访问
4 检查是否可以读访问
6 检查是否可以读/写访问
当允许做指定的访问时,返回0否则返回-1
程序例:
#include 
#include 

int file_exists(char *filename); 

int main(void) 
{ 
printf("Does NOTEXIST.FIL exist: %s\n", 
file_exists("NOTEXISTS.FIL") ? "YES" : "NO"); 
return 0; 
} 

int file_exists(char *filename) 
{ 
return (access(filename, 0) == 0); 
} 

==========
==========
cgets
==========
==========
_chmod
==========
==========
chmod
==========
==========
clearerr
==========
==========
close
==========
==========
cprintf
==========
==========
creat
==========
==========
_creat
==========
==========
creatnew
==========
==========
creattemp
==========
==========
abort
程序例:
#include 
#include 

int main(void) 
{ 
printf("Calling abort()\n"); 
abort(); 
return 0; /* This is never reached */ 
} 

==========
==========
abs
说明:
函数abs( )的原型在math.h中
返回X的绝对值
程序例:
#include 
#include 

int main(void) 
{ 
int number = -1234; 

printf("number: %d absolute value: %d\n", number, abs(number)); 
return 0; 
} 


==========
==========
absread, abswirte
函数absread( ),abswrite( )分别执行对磁盘的无条件的读和写操作,它们越过磁盘的逻辑结构,忽略文件或目录,直接在sectno 
指定的磁盘扇区上操作,驱动器由drive指定,用0代表A驱动器,要读或写的扇区数目由
信息的存储区域由buffer指定。
程序例:
/* absread example */ 

#include 
#include 
#include 
#include 

int main(void) 
{ 
int i, strt, ch_out, sector; 
char buf[512]; 

printf("Insert a diskette into drive A and press any key\n"); 
getch(); 
sector = 0; 
if (absread(0, 1, sector, &buf) != 0) 
{ 
perror("Disk problem"); 
exit(1); 
} 
printf("Read OK\n"); 
strt = 3; 
for (i=0; i<80; i++) 
{ 
ch_out = buf[strt+i]; 
putchar(ch_out); 
} 
printf("\n"); 
return(0); 
} 

==========
==========
acos
程序例:
#include 
#include 

int main(void) 
{ 
double result; 
double x = 0.5; 

result = acos(x); 
printf("The arc cosine of %lf is %lf\n", x, result); 
return 0; 
} 
==========
==========
allocmem
说明:
函数allocmem( )的原型在dos.h中
函数allocmem( )利用DOS调用0X48中断,以分配按节排列的内存块,它把内存块的段地址放进SEG所指的无符号整型数。参数SIZE指定
被分配的节数(一个节是16字节),如果所请求的内存能够被分配,该函数就返回-1,如果没有足够的自由内存,则指向SEG的无符号整型量将不被
赋值,并且返回最大可用块的大小。
程序例:
#include 
#include 
#include 

int main(void) 
{ 
unsigned int size, segp; 
int stat; 

size = 64; /* (64 x 16) = 1024 bytes */ 
stat = allocmem(size, &segp); 
if (stat == -1) 
printf("Allocated memory at segment: %x\n", segp); 
else 
printf("Failed: maximum number of paragraphs available is %u\n", 
stat); 

return 0; 
} 

==========
==========
arc
程序例:
#include 
#include 
#include 
#include 

int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; 
int midx, midy; 
int stangle = 45, endangle = 135; 
int radius = 100; 

/* initialize graphics and local variables */ 
initgraph(&gdriver, &gmode, ""); 

/* read result of initialization */ 
errorcode = graphresult(); /* an error occurred */ 
if (errorcode != grOk) 
{ 
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 
printf("Press any key to halt:"); 
getch(); 

exit(1); /* terminate with an error code */ 
} 

midx = getmaxx() / 2; 
midy = getmaxy() / 2; 
setcolor(getmaxcolor()); 

/* draw arc */ 
arc(midx, midy, stangle, endangle, radius); 

/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} 



==========
==========
asctime
说明:函数原型在time.h中
asctime()用于返回指向一个字符串的指针,由block所指向的结构指针中的时间信息被转换成下面这种这符串形式:
星期  月   日   小时:分:秒   年
例如:wed jun 19 12:05:34 1999
传给asctime()的结构指针一般通过函数localtime()或gmtime()获取
asctime()函数用来保存经格式化的输出字符串的缓冲还是一个静态分配的字符数组,并在每次调用该函数时
被重写,如果要保存这一字符串的内容,必须把它拷贝到其他地方
程序例:
#include  <time.h>


int main(void) 
{ 
struct tm t; 
char str[80]; 

/* sample loading of tm structure */ 

t.tm_sec = 1; /* Seconds */ 
t.tm_min = 30; /* Minutes */ 
t.tm_hour = 9; /* Hour */ 
t.tm_mday = 22; /* Day of the Month */ 
t.tm_mon = 11; /* Month */ 
t.tm_year = 56; /* Year - does not include century */ 
t.tm_wday = 4; /* Day of the week */ 
t.tm_yday = 0; /* Does not show in asctime */ 
t.tm_isdst = 0; /* Is Daylight SavTime; does not show in asctime */ 

/* converts structure to null terminated 
string */ 

strcpy(str, asctime(&t)); 
printf("%s\n", str); 

return 0; 
} 


==========
==========
asin
程序例:
#include 
#include 

int main(void) 
{ 
double result; 
double x = 0.5; 

result = asin(x); 
printf("The arc sin of %lf is %lf\n", x, result); 
return(0); 
} 

==========
==========
assert
说明:其函数原型在assert.h中
assert( )是一个可扩展的IF语句的宏,如果参数TEST的值为0,assert()将在stderr上输出
一条错误信息,并调用Abort()函数中的程序执行,输入的信息为:
Assertion failed:test,file filename,line linenum
其中filename是源文件名,linenum是Assert()出现的行号,如果在#include 〈assert.h>指令代码
之前的代码中有#define NDEBUG指令,其作用是对assert()语句进行注解,亦即这是assert不起作用
程序例:
#include 
#include 
#include 

struct ITEM { 
int key; 
int value; 
}; 

/* add item to list, make sure list is not null */ 
void additem(struct ITEM *itemptr) { 
assert(itemptr != NULL); 
/* add item to list */ 
} 

int main(void) 
{ 
additem(NULL); 
return 0; 
} 


==========
==========
atan
程序例:
#include 
#include 

int main(void) 
{ 
double result; 
double x = 0.5; 

result = atan(x); 
printf("The arc tangent of %lf is %lf\n", x, result); 
return(0); 
} 


==========
==========
atan2
程序例:
#include 
#include 

int main(void) 
{ 
double result; 
double x = 90.0, y = 45.0; 

result = atan2(y, x); 
printf("The arc tangent ratio of %lf is %lf\n", (y / x), result); 
return 0; 
} 
==========
==========
atexit
说明:atexit的原型在stdlib.H  和 process.h中
函数atexit()使得由func所指向的函数作为程序正常终止的调用函数,即指定的函数在程序结束时被调用,
按ANSI标准,这种建立函数调用顺序被称为登记。被调用的函数是atexit_t型,该类函数在stdlib中的typedef中已定义
函数atexit()如指定的终止函数被登记,则返回0,否则返回非0
最多只能建立32个终止函数,它们是以其建立时的相反顺序被调用的,即先进后出。
程序例:
#include 
#include 

void exit_fn1(void) 
{ 
printf("Exit function #1 called\n"); 
} 

void exit_fn2(void) 
{ 
printf("Exit function #2 called\n"); 
} 

int main(void) 
{ 
/* post exit function #1 */ 
atexit(exit_fn1); 
/* post exit function #2 */ 
atexit(exit_fn2); 
return 0; 
} 



==========
==========
atof
说明:atof()函数的原型在math.H  和 stdlib.h中
函数atof()把由nptr所指向的字符串变成一个双精度值,该字符串必须包含一个有效的实型数。
如果不是这样,则返回0,该数值可以为任何字符结尾,但不能是有效实型数部分,包括空白符号,
标点符号(除句点以外),和除字母e中E以外的其它字符,这意味着,如果atof()用100.00hello调用,
则返回值为100.00
程序例:
#include 
#include 

int main(void) 
{ 
float f; 
char *str = "12345.67"; 

f = atof(str); 
printf("string = %s float = %f\n", str, f); 
return 0; 
} 

==========
==========
atoi
说明:atoi()函数的原型在stdlib.h中
函数atoi()将由nptr所指向的字符串换为整型值,该字符串必须包含一个有效整型值。如果不是这样,就返回0
该数值可以为任何字符结尾,但不能是整型数的有效部分,包括空白符号,
标点符号(除句点以外),和除字母e中E以外的其它字符,这意味着,如果atoi()用123.23调用,
则返回值为123

程序例:
#include 
#include 

int main(void) 
{ 
int n; 
char *str = "12345.67"; 

n = atoi(str); 
printf("string = %s integer = %d\n", str, n); 
return 0; 
} 


==========
==========
atol
说明:
atol()函数的原型在stdlib中
函数atol()所由nptr所指向的字符串换成一个长整型,该字符中包含一个有效长整型数,如不是这样,则返回0
该数值可以为任何字符结尾,但不能是整型数的有效部分,包括空白符号,
标点符号(除句点以外),和除字母e中E以外的其它字符,这意味着,如果atol()用123.23调用,
则返回值为123

程序例:

#include 
#include 

int main(void) 
{ 
long l; 
char *str = "98765432"; 

l = atol(lstr); 
printf("string = %s integer = %ld\n", str, l); 
return(0); 
}

==========
==========
bar

说明:函数原型在
程序例:

#include <graphics.h>


int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; 
int midx, midy, i; 

/* initialize graphics and local variables */ 
initgraph(&gdriver, &gmode, ""); 

/* 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 */ 
} 

midx = getmaxx() / 2; 
midy = getmaxy() / 2; 

/* loop through the fill patterns */ 
for (i=SOLID_FILL; i { 
/* set the fill style */ 
setfillstyle(i, getmaxcolor()); 

/* draw the bar */ 
bar(midx-50, midy-50, midx+50, 
midy+50); 

getch(); 
} 

/* clean up */ 
closegraph(); 
return 0; 
} 

==========
==========
bar3d
说明:函数原型在graphics.h中
函数bar3d()除了产生一个以depth为象素的三维条形外,其它与bar()一样,条形是以当前画线颜色画出其外廓
这意味着,如果你要画一个有外廓线的二维条形,就用Bar3d()函数并将depth设为0,参数topflag决定是否在条形
图上放上一个三维的顶,如果其不为0,则放上一个顶盖,否则该条形无顶盖

程序例:

#include 
#include 
#include 
#include 

int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; 
int midx, midy, i; 

/* initialize graphics, local variables */ 
initgraph(&gdriver, &gmode, ""); 

/* 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 error code */ 
} 

midx = getmaxx() / 2; 
midy = getmaxy() / 2; 

/* loop through the fill patterns */ 
for (i=EMPTY_FILL; i { 
/* set the fill style */ 
setfillstyle(i, getmaxcolor()); 

/* draw the 3-d bar */ 
bar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); 

getch(); 
} 

/* clean up */ 
closegraph(); 
return 0; 
} 


==========
==========
bdos
说明:bdos()的原型在dos.h中
这个函数不是ANSI标准的一员
函数bdos用来访问由
如果要把指针参数传给DOS,就使用bdosptr()函数来代替bdos()。
Bdos()和bdosptr()都返回AX寄存器的值,DOS使用该值来返回信息。
程序例:

#include 
#include 

/* Get current drive as 'A', 'B', ... */ 
char current_drive(void) 
{ 
char curdrive; 

/* Get current disk as 0, 1, ... */ 
curdrive = bdos(0x19, 0, 0); 
return('A' + curdrive); 
} 

int main(void) 
{ 
printf("The current drive is %c:\n", current_drive()); 
return 0; 
} 


==========
==========
bdosptr
程序例:

#include <dos.h>

#define BUFLEN 80 

int main(void) 
{ 
char buffer[BUFLEN]; 
int test; 

printf("Enter full pathname of a directory\n"); 
gets(buffer); 

test = bdosptr(0x3B,buffer,0); 
if(test) 
{ 
printf("DOS error message: %d\n", errno); 
/* See errno.h for error listings */ 
exit (1); 
} 

getcwd(buffer, BUFLEN); 
printf("The current directory is: %s\n", buffer); 

return 0; 
} 

==========
==========
bioscom
程序例:

#include 
#include 

#define COM1 0 
#define DATA_READY 0x100 
#define TRUE 1 
#define FALSE 0 

#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00) 

int main(void) 
{ 
int in, out, status, DONE = FALSE; 

bioscom(0, SETTINGS, COM1); 
cprintf("... BIOSCOM [ESC] to exit ...\n"); 
while (!DONE) 
{ 
status = bioscom(3, 0, COM1); 
if (status & DATA_READY) 
if ((out = bioscom(2, 0, COM1) & 0x7F) != 0) 
putch(out); 
if (kbhit()) 
{ 
if ((in = getch()) == '\x1B') 
DONE = TRUE; 
bioscom(1, in, COM1); 
} 
} 
return 0; 
} 

==========
==========
biosdisk
说明:该函数的原型在bios.h中
函数biosdisk()使用0X13中断来完成BIOS级的磁盘操作,这些操作忽略磁盘文件及文件的逻辑结构,所有的操作作用于扇区
用drive来指定目标驱动器,以0对应于A,1对应于B这种方式来指定软盘驱动器。对于硬盘,第1个硬盘驱动器号为0x80,第二个
是0X81以此类推,被操作的磁盘区域由head,track,sector指定,你应该参阅IBM PC的技术参考手册,以便详细了解操作方法。最好避免
使用这类操作,除非性况很特别
程序例:

#include 
#include 

int main(void) 
{ 
int result; 
char buffer[512]; 

printf("Testing to see if drive a: is ready\n"); 
result = biosdisk(4,0,0,0,0,1,buffer); 
result &= 0x02; 
(result) ? (printf("Drive A: Ready\n")) : 
(printf("Drive A: Not Ready\n")); 

return 0; 
} 



==========
==========
biosequip
==========
==========
bioskey
==========
==========
biosmemory
==========
==========
biosprint
==========
==========
biostime
==========
==========
brk
==========
==========
bsearch
==========
==========
cabs
==========
==========
calloc
==========
==========
ceil
==========
==========
chdir
==========
==========
chsize
==========
==========
circle
==========
==========
cleardevice
==========
==========
clearviewport
==========
==========
clock
==========
==========
closegraph
==========
==========
clreol
==========
==========
clrscr
==========
==========
coreleft
==========
==========
cos
==========
==========
cosh
==========
==========
country
==========
==========
cputs
==========
==========
cscanf
==========
==========
ctime
==========
==========
ctrlbrk
==========
==========
cabs
==========
==========
calloc
==========
==========
ceil
==========
==========
cgets
==========
==========
chdir
==========
==========
_chmod, chmod
==========
==========
chsize
==========
==========
circle
==========
==========
cleardevice
==========
==========
clearerr
==========
==========
clearviewport
==========
==========
_close, close
==========
==========
clock
==========
==========
closegraph
==========
==========
clreol
==========
==========
clrscr
==========
==========
coreleft
==========
==========
cos
==========
==========
cosh
==========
==========
country
==========
==========
cprintf
==========
==========
cputs
==========
==========
_creat creat
==========
==========
creatnew
==========
==========
creattemp
==========
==========
cscanf
==========
==========
ctime
==========
==========
ctrlbrk
==========
==========
delay
==========
==========
delline
==========
==========
detectgraph
==========
==========
difftime
==========
==========
disable
==========
==========
div
==========
==========
doterr
==========
==========
dostounix
==========
==========
drawpoly
==========
==========
dup

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -