博文
函数大全(k开头)(2006-06-16 10:00:00)
摘要:函数名: kbhit 功 能: 检查当前按下的键 用 法: int kbhit(void); 程序例:
#include
int main(void) { cprintf("Press any key to continue:"); while (!kbhit()) /* do nothing */ ; cprintf("\r\nA key was pressed...\r\n"); return 0; }
函数名: keep 功 能: 退出并继续驻留 用 法: void keep(int status, int size); 程序例:
/***NOTE: This is an interrupt service routine. You can NOT compile this program with Test Stack Overflow turned on and get an executable file which will operate correctly. Due to the nature of this function the formula used to compute the number of paragraphs may not necessarily work in all cases. Use with care! Terminate Stay Resident (TSR) programs are complex and no other support for them is provided. Refer to the MS-DOS technical documentation for more information. */ #include /* The clock tick interrupt */ #define INTR 0x1C /* Screen attribute (blue on grey) */ #define ATTR 0x7900
/* reduce heaplength and stacklength to make a smaller program in memory */ extern unsigned _heaplen = 1024; extern unsigned......
函数大全(l开头)(2006-06-16 09:59:00)
摘要:
函数名: labs 用 法: long labs(long n); 程序例:
#include #include
int main(void) { long result; long x = -12345678L;
result= labs(x); printf("number: %ld abs value: %ld\n", x, result);
return 0; }
函数名: ldexp 功 能: 计算value*2的幂 用 法: double ldexp(double value, int exp); 程序例:
#include #include
int main(void) { double value; double x = 2;
/* ldexp raises 2 by a power of 3 then multiplies the result by 2 */ value = ldexp(x,3); printf("The ldexp value is: %lf\n", value);
return 0; }
函数名: ldiv 功 能: 两个长整型数相除, 返回商和余数 用 法: ldiv_t ldiv(long lnumer, long ldenom); 程序例:
/* ldiv example */
#include #include
int main(void) { ldiv_t lx;
lx = ldiv(100000L, 30000L); printf("100000 div 30000 = %ld remainder %ld\n", lx.quot, lx.rem); return 0; }
函数名: lfind 功 能: 执行线性搜索 用 法: void *lfind(void *key, void *base, int *nelem, int width, int (*fcmp)()); 程序例:
#include #include
int compare(int *x, int *y) { return( *x - *y ); }
int main(void) { int array[5] = {35, 87, 46, 99, 12}; si......
函数大全(m开头)(2006-06-16 09:58:00)
摘要:main()主函数每一C 程序都 必须 有一main()函数, 可以根据自己的爱好把它放在程序的某 个地方。有些程序员把它放在最前面, 而另一些程序员把它放在最后面, 无论放 在哪个地方, 以下几点说明都是适合的。 1. main() 参数 在Turbo C2.0启动过程中, 传递main()函数三个参数: argc, argv和env。 * argc: 整数, 为传给main()的命令行参数个数。 * argv: 字符串数组。 在DOS 3.X 版本中, argv[0] 为程序运行的全路径名; 对DOS 3.0 以下的版本, argv[0]为空串("") 。 argv[1] 为在DOS命令行中执行程序名后的第一个字符串; argv[2] 为执行程序名后的第二个字符串; ... argv[argc]为NULL。 *env: 安符串数组。env[] 的每一个元素都包含ENVVAR=value形式的字符 串。其中ENVVAR为环境变量如PATH或87。value 为ENVVAR的对应值如C:\DOS, C: \TURBOC(对于PATH) 或YES(对于87)。 Turbo C2.0启动时总是把这三个参数传递给main()函数, 可以在用户程序中 说明(或不说明)它们, 如果说明了部分(或全部)参数, 它们就成为main()子程序 的局部变量。 请注意: 一旦想说明这些参数, 则必须按argc, argv, env 的顺序, 如以下 的例子: main() main(int argc) main(int argc, char *argv[]) main(int argc, char *argv[], char *env[]) 其中第二种情况是合法的, 但不常见, 因为在程序中很少有只用argc, 而不 用argv[]的情况。 以下提供一样例程序EXAMPLE.EXE, 演示如何在main()函数中使用三个参数: /*program name EXAMPLE.EXE*/ #include #include main(int argc, char *argv[], char *env[]) { int i; printf("These are the %d command- line arguments passed to main:\n\n", argc); for(i=......
函数大全(n ,o开头)(2006-06-16 09:55:00)
摘要:void normvideo(void );选择正常亮度字符。将文本属性(前景和背景)置为启动程序时它所具有的值,来选择标准字符。
void nosound(void );关闭由调用 sound而发声的扬声器。
函数名: open 功 能: 打开一个文件用于读或写 用 法: int open(char *pathname, int access[, int permiss]); 程序例:
#include #include #include #include
int main(void) { int handle; char msg[] = "Hello world";
if ((handle = open("TEST.$$$", O_CREAT | O_TEXT)) == -1) { perror("Error:"); return 1; } write(handle, msg, strlen(msg)); close(handle); return 0; }
函数名: outport 功 能: 输出整数到硬件端口中 用 法: void outport(int port, int value); 程序例:
#include #include int main(void) { int value = 64; int port = 0;
outportb(port, value); printf("Value %d sent to port number %d\n", value, port); return 0; }
函数名: outportb 功 能: 输出字节到硬件端口中 用 法: void outportb(int port, char byte); 程序例:
#include #include
int main(void) { int value = 64; int port = 0;
outportb(port, value); printf("Value %d sent to port number %d\n", value, port); return 0; }
函数名: outtext 功 能: 在视区显示一个字符串 用 法: void far outtext(char far *textstrin......
函数大全(p开头)(2006-06-16 09:53:00)
摘要:函数名: parsfnm 功 能: 分析文件名 用 法: char *parsfnm (char *cmdline, struct fcb *fcbptr, int option); 程序例:
#include #include #include #include
int main(void) { char line[80]; struct fcb blk;
/* get file name */ printf("Enter drive and file name (no path - ie. a:file.dat)\n"); gets(line);
/* put file name in fcb */ if (parsfnm(line, &blk, 1) == NULL) printf("Error in parsfm call\n"); else printf("Drive #%d Name: %11s\n", blk.fcb_drive, blk.fcb_name);
return 0; }
函数名: peek 功 能: 检查存储单元 用 法: int peek(int segment, unsigned offset); 程序例:
#include #include #include
int main(void) { int value = 0;
printf("The current status of your keyboard is:\n"); value = peek(0x0040, 0x0017); if (value & 1) printf("Right shift on\n"); else printf("Right shift off\n");
if (value & 2) printf("Left shift on\n"); else printf("Left shift off\n");
if (value & 4) printf("Control key on\n"); else printf("Control key off\n");
if (value & 8) printf("Alt key on\n"); else printf("Alt k......
函数大全(q,r开头)(2006-06-16 09:49:00)
摘要:函数名: qsort 功 能: 使用快速排序例程进行排序 用 法: void qsort(void *base, int nelem, int width, int (*fcmp)()); 程序例:
#include #include #include
int sort_function( const void *a, const void *b);
char list[5][4] = { "cat", "car", "cab", "cap", "can" };
int main(void) { int x;
qsort((void *)list, 5, sizeof(list[0]), sort_function); for (x = 0; x < 5; x++) printf("%s\n", list[x]); return 0; }
int sort_function( const void *a, const void *b) { return( strcmp(a,b) ); }
函数名: qsort 功 能: 使用快速排序例程进行排序 用 法: void qsort(void *base, int nelem, int width, int (*fcmp)()); 程序例:
#include #include #include
int sort_function( const void *a, const void *b);
char list[5][4] = { "cat", "car", "cab", "cap", "can" };
int main(void) { int x;
qsort((void *)list, 5, sizeof(list[0]), sort_function); for (x = 0; x < 5; x++) printf("%s\n", list[x]); return 0; }
int sort_function( const void *a, const void *b) { return( strcmp(a,b) ); }
函数名: raise 功 能: 向正在执行的程序发送一个信号 用 法: int raise(int sig); 程序例......
函数大全(s开头)(2006-06-16 09:48:00)
摘要:函数名: sbrk 功 能: 改变数据段空间位置 用 法: char *sbrk(int incr); 程序例:
#include #include
int main(void) { printf("Changing allocation with sbrk()\n"); printf("Before sbrk() call: %lu bytes free\n", (unsigned long) coreleft()); sbrk(1000); printf(" After sbrk() call: %lu bytes free\n", (unsigned long) coreleft()); return 0; }
函数名: scanf 功 能: 执行格式化输入 用 法: int scanf(char *format[,argument,...]); 程序例:
#include #include
int main(void) { char label[20]; char name[20]; int entries = 0; int loop, age; double salary;
struct Entry_struct { char name[20]; int age; float salary; } entry[20];
/* Input a label as a string of characters restricting to 20 characters */ printf("\n\nPlease enter a label for the chart: "); scanf("%20s", label); fflush(stdin); /* flush the input stream in case of bad input */
/* Input number of entries as an integer */ printf("How many entries will there be? (less than 20) "); scanf("%d", &entries); fflush(stdin); /* flush the input stream in case of bad input */
......
函数大全(t开头)(2006-06-16 09:46:00)
摘要:函数名: tan 功 能: 正切函数 用 法: double tan(double x); 程序例:
#include #include
int main(void) { double result, x;
x = 0.5; result = tan(x); printf("The tan of %lf is %lf\n", x, result); return 0; }
函数名: tanh 功 能: 双曲正切函数 用 法: double tanh(double x); 程序例:
#include #include
int main(void) { double result, x;
x = 0.5; result = tanh(x); printf("The hyperbolic tangent of %lf is %lf\n", x, result); return 0; }
函数名: tell 功 能: 取文件指针的当前位置 用 法: long tell(int handle); 程序例:
#include #include #include #include
int main(void) { int handle; char msg[] = "Hello world";
if ((handle = open("TEST.$$$", O_CREAT | O_TEXT | O_APPEND)) == -1) { perror("Error:"); return 1; } write(handle, msg, strlen(msg)); printf("The file pointer is at byte %ld\n", tell(handle)); close(handle); return 0; }
函数名: textattr 功 能: 设置文本属性 用 法: void textattr(int attribute); 程序例:
#include
int main(void) { int i;
clrscr(); for (i=0; i<9; i++) { textattr(i + ((i+1) << 4)); cprintf("This is a test\r\n"); }
......
函数大全(u开头)(2006-06-16 09:44:00)
摘要:函数名: ultoa 功 能: 转换一个无符号长整型数为字符串 用 法: char *ultoa(unsigned long value, char *string, int radix); 程序例:
#include #include
int main( void ) { unsigned long lnumber = 3123456789L; char string[25];
ultoa(lnumber,string,10); printf("string = %s unsigned long = %lu\n",string,lnumber);
return 0; }
函数名: ungetc 功 能: 把一个字符退回到输入流中 用 法: int ungetc(char c, FILE *stream); 程序例:
#include #include
int main( void ) { int i=0; char ch;
puts("Input an integer followed by a char:");
/* read chars until non digit or EOF */ while((ch = getchar()) != EOF && isdigit(ch)) i = 10 * i + ch - 48; /* convert ASCII into int value */
/* if non digit char was read, push it back into input buffer */ if (ch != EOF) ungetc(ch, stdin);
printf("i = %d, next char in buffer = %c\n", i, getchar()); return 0; }
函数名: ungetch 功 能: 把一个字符退回到键盘缓冲区中 用 法: int ungetch(int c); 程序例:
#include #include #include
int main( void ) { int i=0; char ch;
puts("Input an integer followed by a char:");
/* read ......
函数大全(v开头)(2006-06-16 09:43:00)
摘要:函数名: vfprintf 功 能: 送格式化输出到一流中 用 法: int vfprintf(FILE *stream, char *format, va_list param); 程序例:
#include #include #include
FILE *fp;
int vfpf(char *fmt, ...) { va_list argptr; int cnt;
va_start(argptr, fmt); cnt = vfprintf(fp, fmt, argptr); va_end(argptr);
return(cnt); }
int main(void) { int inumber = 30; float fnumber = 90.0; char string[4] = "abc";
fp = tmpfile(); if (fp == NULL) { perror("tmpfile() call"); exit(1); }
vfpf("%d %f %s", inumber, fnumber, string); rewind(fp); fscanf(fp,"%d %f %s", &inumber, &fnumber, string); printf("%d %f %s\n", inumber, fnumber, string); fclose(fp);
return 0; }
函数名: vfscanf 功 能: 从流中执行格式化输入 用 法: int vfscanf(FILE *stream, char *format, va_list param); 程序例:
#include #include #include
FILE *fp;
int vfsf(char *fmt, ...) { va_list argptr; int cnt;
va_start(argptr, fmt); cnt = vfscanf(fp, fmt, argptr); va_end(argptr);
return(cnt); }
int main(void) { int inumber = 30; float fnumber = 90.0; char string[4] = "abc";
fp ......
