博文
函数大全(t开头)(2006-11-27 20:06: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......
函数大全(s开头)(2006-11-27 20:06: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......
函数大全(q,r开头)(2006-11-27 20:01: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(i......
函数大全(p开头)(2006-11-27 19:59: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 p......
函数大全(n ,o开头)(2006-11-27 19:58: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 fa......
函数大全(m开头)(2006-11-27 19:57: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", a......
函数大全(l开头)(2006-11-27 19:56: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,......
函数大全(k开头)(2006-11-27 19:54: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; ext......
函数大全(i开头)(2006-11-27 19:51:00)
摘要:
函数名: imagesize 功 能: 返回保存位图像所需的字节数 用 法: unsigned far imagesize(int left, int top, int right, int bottom); 程序例:
#include #include #include #include
#define ARROW_SIZE 10
void draw_arrow(int x, int y);
int main(void) { /* request autodetection */ int gdriver = DETECT, gmode, errorcode; void *arrow; int x, y, maxx; unsigned int size;
/* 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 */ }
maxx = getmaxx(); x = 0; y = getmaxy() / 2;
/* draw the image to be grabbed */ draw_arrow(x, y);
/* calculate the size of the image */ size = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE);
/* allocate memory to hold the image */ arrow = malloc(size);
/* grab the image */ get......
函数大全(h开头)(2006-11-27 19:50:00)
摘要:
函数名: harderr 功 能: 建立一个硬件错误处理程序 用 法: void harderr(int (*fptr)()); 程序例: /*This program will trap disk errors and prompt the user for action. Try running it with no disk in drive A: to invoke its functions.*/
#include #include #include #define IGNORE 0 #define RETRY 1 #define ABORT 2 int buf[500]; /*define the error messages for trapping disk problems*/ static char *err_msg[] = { "write protect", "unknown unit", "drive not ready", "unknown command", "data error (CRC)", "bad request", "seek error", "unknown media type", "sector not found", "printer out of paper", "write fault", "read fault", "general failure", "reserved", "reserved", "invalid disk change" };
error_win(char *msg) { int retval;
cputs(msg);
/*prompt for user to press a key to abort, retry, ignore*/ while(1) { retval= getch(); if (retval == 'a' || retval == 'A') { retval = ABORT; break; } if (retval == 'r' || retval == 'R') { retval = RETRY; break; } if (retval == 'i' || retval == 'I') { retval = IGNORE; br......
