为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

C语言函数

2012-02-10 50页 doc 127KB 48阅读

用户头像

is_562314

暂无简介

举报
C语言函数 函数名: gcvt 功  能: 把浮点数转换成字符串 用  法: char *gcvt(double value, int ndigit, char *buf); 程序例: #include #include int main(void) {    char str[25];    double num;    int sig = 5; /* significant digits */    /* a regular number */    num = 9.876;    gcvt(num, sig, str...
C语言函数
函数名: gcvt 功  能: 把浮点数转换成字符串 用  法: char *gcvt(double value, int ndigit, char *buf); 程序例: #include #include int main(void) {    char str[25];    double num;    int sig = 5; /* significant digits */    /* a regular number */    num = 9.876;    gcvt(num, sig, str);    printf("string = %s\n", str);    /* a negative number */    num = -123.4567;    gcvt(num, sig, str);    printf("string = %s\n", str);    /* scientific notation */    num = 0.678e5;    gcvt(num, sig, str);    printf("string = %s\n", str);    return(0); } 函数名: geninterrupt 功  能: 产生一个软中断 用  法: void geninterrupt(int intr_num); 程序例: #include #include /* function prototype */ void writechar(char ch); int main(void) {    clrscr();    gotoxy(80,25);    writechar('*');    getch();    return 0; } /*    outputs a character at the current cursor    position using the video BIOS to avoid the    scrolling of the screen when writing to    location (80,25). */ void writechar(char ch) {    struct text_info ti;    /* grab current text settings */    gettextinfo(&ti);    /* interrupt 0x10 sub-function 9 */    _AH = 9;    /* character to be output */    _AL = ch;    _BH = 0;                  /* video page */    _BL = ti.attribute;  /* video attribute */    _CX = 1;           /* repetition factor */    geninterrupt(0x10);  /* output the char */ } 函数名: getarccoords 功  能: 取得最后一次调用arc的坐标 用  法: void far getarccoords(struct arccoordstype far *arccoords); 程序例: #include #include #include #include int main(void) { /* request auto detection */    int gdriver = DETECT, gmode, errorcode;    struct arccoordstype arcinfo;    int midx, midy;    int stangle = 45, endangle = 270;    char sstr[80], estr[80]; /* 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(); /* terminate with an error code */       exit(1);    }    midx = getmaxx() / 2;    midy = getmaxy() / 2; /* draw arc and get coordinates */    setcolor(getmaxcolor());    arc(midx, midy, stangle, endangle, 100);    getarccoords(&arcinfo); /* convert arc information into strings */    sprintf(sstr, "*- (%d, %d)",            arcinfo.xstart, arcinfo.ystart);    sprintf(estr, "*- (%d, %d)",            arcinfo.xend, arcinfo.yend);    /* output the arc information */    outtextxy(arcinfo.xstart,              arcinfo.ystart, sstr);    outtextxy(arcinfo.xend,              arcinfo.yend, estr);    /* clean up */    getch();    closegraph();    return 0; } 函数名: getaspectratio 功  能: 返回当前图形模式的纵横比 用  法: void far getaspectratio(int far *xasp, int far *yasp); 程序例: #include #include #include #include int main(void) { /* request auto detection */    int gdriver = DETECT, gmode, errorcode;    int xasp, yasp, midx, midy; /* 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(); /* terminate with an error code */       exit(1);    }    midx = getmaxx() / 2;    midy = getmaxy() / 2;    setcolor(getmaxcolor()); /* get current aspect ratio settings */    getaspectratio(&xasp, &yasp); /* draw normal circle */    circle(midx, midy, 100);    getch(); /* draw wide circle */    cleardevice();    setaspectratio(xasp/2, yasp);    circle(midx, midy, 100);    getch(); /* draw narrow circle */    cleardevice();    setaspectratio(xasp, yasp/2);    circle(midx, midy, 100); /* clean up */    getch();    closegraph();    return 0; } 函数名: getbkcolor 功  能: 返回当前背景颜色 用  法: int far getbkcolor(void); 程序例: #include #include #include #include #include int main(void) {    /* request auto detection */    int gdriver = DETECT, gmode, errorcode;    int bkcolor, midx, midy;    char bkname[35]; /* 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(); /* terminate with an error code */       exit(1);    }    midx = getmaxx() / 2;    midy = getmaxy() / 2;    setcolor(getmaxcolor()); /* for centering text on the display */    settextjustify(CENTER_TEXT, CENTER_TEXT); /* get the current background color */    bkcolor = getbkcolor(); /* convert color value into a string */    itoa(bkcolor, bkname, 10);    strcat(bkname,  " is the current background color."); /* display a message */    outtextxy(midx, midy, bkname); /* clean up */    getch();    closegraph();    return 0; } 函数名: getc 功  能: 从流中取字符 用  法: int getc(FILE *stream); 程序例: #include int main(void) {    char ch;    printf("Input a character:"); /* read a character from the    standard input stream */    ch = getc(stdin);    printf("The character input was: '%c'\n",           ch);    return 0; }  函数名: getcbrk 功  能: 获取Control_break设置 用  法: int getcbrk(void); 程序例: #include #include int main(void) {    if (getcbrk())       printf("Cntrl-brk flag is on\n");    else       printf("Cntrl-brk flag is off\n");    return 0; }  函数名: getch 功  能: 从控制台无回显地取一个字符 用  法: int getch(void); 程序例: #include #include int main(void) {    char ch;    printf("Input a character:");    ch = getche();    printf("\nYou input a '%c'\n", ch);    return 0; } 函数名: getchar 功  能: 从stdin流中读字符 用  法: int getchar(void); 程序例: #include int main(void) {    int c;    /* Note that getchar reads from stdin and       is line buffered; this means it will       not return until you press ENTER. */    while ((c = getchar()) != '\n')       printf("%c", c);    return 0; } 函数名: getche 功  能: 从控制台取字符(带回显) 用  法: int getche(void); 程序例: #include #include int main(void) {    char ch;    printf("Input a character:");    ch = getche();    printf("\nYou input a '%c'\n", ch);    return 0; } 函数名: getcolor 功  能: 返回当前画线颜色 用  法: int far getcolor(void); 程序例: #include #include #include #include #include int main(void) { /* request auto detection */    int gdriver = DETECT, gmode, errorcode;    int color, midx, midy;    char colname[35]; /* 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(); /* terminate with an error code */       exit(1);    }    midx = getmaxx() / 2;    midy = getmaxy() / 2;    setcolor(getmaxcolor()); /* for centering text on the display */    settextjustify(CENTER_TEXT, CENTER_TEXT); /* get the current drawing color */    color = getcolor(); /* convert color value into a string */    itoa(color, colname, 10);    strcat(colname,    " is the current drawing color."); /* display a message */    outtextxy(midx, midy, colname); /* clean up */    getch();    closegraph();    return 0; } 函数名: getcurdir 功  能: 取指定驱动器的当前目录 用  法: int getcurdir(int drive, char *direc); 程序例: #include #include #include char *current_directory(char *path) {    strcpy(path, "X:\\");      /* fill string with form of response: X:\ */    path[0] = 'A' + getdisk();    /* replace X with current drive letter */    getcurdir(0, path+3);  /* fill rest of string with current directory */    return(path); } int main(void) {    char curdir[MAXPATH];    current_directory(curdir);    printf("The current directory is %s\n", curdir);    return 0; }  函数名: getcwd 功  能: 取当前工作目录 用  法: char *getcwd(char *buf, int n); 程序例: #include #include int main(void) {    char buffer[MAXPATH];    getcwd(buffer, MAXPATH);    printf("The current directory is: %s\n", buffer);    return 0; }  函数名: getdate 功  能: 取DOS日期 用  法: void getdate(struct *dateblk); 程序例: #include #include int main(void) {    struct date d;    getdate(&d);    printf("The current year is: %d\n",    d.da_year);    printf("The current day is: %d\n",    d.da_day);    printf("The current month is: %d\n",    d.da_mon);    return 0; }  函数名: getdefaultpalette 功  能: 返回调色板定义结构 用  法: struct palettetype *far getdefaultpalette(void); 程序例: #include #include #include #include int main(void) { /* request auto detection */    int gdriver = DETECT, gmode, errorcode;    int i; /* structure for returning palette copy */    struct palettetype far *pal=(void *) 0; /* 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(); /* terminate with an error code */       exit(1);    }    setcolor(getmaxcolor()); /* return a pointer to the default palette */    pal = getdefaultpalette();    for (i=0; i<16; i++)    {       printf("colors[%d] = %d\n", i,              pal->colors[i]);       getch();    } /* clean up */    getch();    closegraph();    return 0; } 函数名: getdisk 功  能: 取当前磁盘驱动器号 用  法: int getdisk(void); 程序例: #include #include int main(void) {    int disk;    disk = getdisk() + 'A';    printf("The current drive is: %c\n",     disk);    return 0; }  函数名: getdrivername 功  能: 返回指向包含当前图形驱动程序名字的字符串指针 用  法: char *getdrivename(void); 程序例: #include #include #include #include int main(void) { /* request auto detection */    int gdriver = DETECT, gmode, errorcode; /* stores the device driver name */    char *drivername; /* 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(); /* terminate with an error code */       exit(1);    }    setcolor(getmaxcolor()); /* get name of the device driver in use */    drivername = getdrivername(); /* for centering text on the screen */    settextjustify(CENTER_TEXT, CENTER_TEXT); /* output the name of the driver */    outtextxy(getmaxx() / 2, getmaxy() / 2,       drivername); /* clean up */    getch();    closegraph();    return 0; }     函数名: getdta 功  能: 取磁盘传输地址 用  法: char far *getdta(void); 程序例: #include #include int main(void) {    char far *dta;    dta = getdta();    printf("The current disk transfer \    address is: %Fp\n", dta);    return 0; }  函数名: getenv 功  能: 从环境中取字符串 用  法: char *getenv(char *envvar); 程序例: #include #include   int main(void) {     char *s;     s=getenv("COMSPEC");       /* get the comspec environment parameter */     printf("Command processor: %s\n",s);   /* display comspec parameter */     return 0; }  函数名: getfat, getfatd 功  能: 取文件分配表信息 用  法: void getfat(int drive, struct fatinfo *fatblkp); 程序例: #include #include int main(void) {    struct fatinfo diskinfo;    int flag = 0;    printf("Please insert disk in drive A\n");    getchar();    getfat(1, &diskinfo); /* get drive information */    printf("\nDrive A: is ");    switch((unsigned char) diskinfo.fi_fatid)    {       case 0xFD:  printf("360K low density\n");  break;       case 0xF9:  printf("1.2 Meg high density\n");  break;       default:  printf("unformatted\n");  flag = 1;    }    if (!flag)    {       printf("  sectors per cluster %5d\n",        diskinfo.fi_sclus);       printf("   number of clusters %5d\n",        diskinfo.fi_nclus);       printf("     bytes per sector %5d\n",        diskinfo.fi_bysec);    }    return 0; } 函数名: getfillpattern 功  能: 将用户定义的填充模式拷贝到内存中 用  法: void far getfillpattern(char far *upattern); 程序例: #include #include #include #include int main(void) {    /* request auto detection */    int gdriver = DETECT, gmode, errorcode;    int maxx, maxy;    char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x25, 0x27, 0x04, 0x04};    /* 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();    maxy = getmaxy();    setcolor(getmaxcolor());    /* select a user defined fill pattern */    setfillpattern(pattern, getmaxcolor());    /* fill the screen with the pattern */    bar(0, 0, maxx, maxy);    getch();    /* get the current user defined fill pattern */    getfillpattern(pattern);    /* alter the pattern we grabbed */    pattern[4] -= 1;    pattern[5] -= 3;    pattern[6] += 3;    pattern[7] -= 4;    /* select our new pattern */    setfillpattern(pattern, getmaxcolor());    /* fill the screen with the new pattern */    bar(0, 0, maxx, maxy);    /* clean up */    getch();    closegraph();    return 0; }  函数名: getfillsettings 功  能: 取得有关当前填充模式和填充颜色的信息 用  法: void far getfillsettings(struct fillsettingstype far *fillinfo); 程序例: #include #include #include #include /  the names of the fill styles supported */ char *fname[] = { "EMPTY_FILL",                   "SOLID_FILL",                   "LINE_FILL",                   "LTSLASH_FILL",                   "SLASH_FILL",                   "BKSLASH_FILL",                   "LTBKSLASH_FILL",                   "HATCH_FILL",                   "XHATCH_FILL",                   "INTERLEAVE_FILL",                   "WIDE_DOT_FILL",                   "CLOSE_DOT_FILL",                   "USER_FILL"         }; int main(void) {    /* request auto detection */    int gdriver = DETECT, gmode, errorcode;    struct fillsettingstype fillinfo;    int midx, midy;    char patstr[40], colstr[40];    /* 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;    /* get information about current fill pattern and color */    getfillsettings(&fillinfo);    /* convert fill information into strings */    sprintf(patstr, "%s is the fill style.", fname[fillinfo.pattern]);    sprintf(colstr, "%d is the fill color.", fillinfo.color);    /* display the information */    settextjustify(CENTER_TEXT, CENTER_TEXT);    outtextxy(midx, midy, patstr);    outtextxy(midx, midy+2*textheight("W"), colstr);    /* clean up */    getch();    closegraph();    return 0; } 函数名: getftime 功  能: 取文件日期和时间 用  法: int getftime(int handle, struct ftime *ftimep); 程序例: #include #include int main(void) {    FILE *stream;    struct ftime ft;    if ((stream = fopen("TEST.$$$",         "wt")) == NULL)    {       fprintf(stderr,              "Cannot open output file.\n");       return 1;    }    getftime(fileno(stream), &ft);    printf("File time: %u:%u:%u\n",           ft.ft_hour, ft.ft_min,           ft.ft_tsec * 2);    printf("File date: %u/%u/%u\n",    ft.ft_month, ft.ft_day,    ft.ft_year+1980);    fclose(stream);    return 0; } 函数名: getgraphmode 功  能: 返回当前图形模式 用  法: int far getgraphmode(void); 程序例: #include #include #include #include int main(void) { /* request auto detection */    int gdriver = DETECT, gmode, errorcode;    int midx, midy, mode;    char numname[80], modename[80]; /* 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(); /* terminate with an error code */       exit(1);    }    midx = getmaxx() / 2;    midy = getmaxy() / 2; /* get mode number and name strings */    mode = getgraphmode();    sprintf(numname,            "%d is the current mode number.",            mode);    sprintf(modename,            "%s is the current graphics mode",            getmodename(mode)); /* display the information */    settextjustify(CENTER_TEXT, CENTER_TEXT);    outtextxy(midx, midy, numname);    outtextxy(midx, midy+2*textheight("W"),              modename); /* clean up */    getch();    closegraph();    return 0; }  函数名: getftime 功  能: 取文件日期和时间 用  法: int getftime(int handle, struct ftime *ftimep); 程序例: #include #include int main(void) {    FILE *stream;    struct ftime ft;    if ((stream = fopen("TEST.$$$",         "wt")) == NULL)    {       fprintf(stderr,              "Cannot open output file.\n");       return 1;    }    getftime(fileno(stream), &ft);    printf("File time: %u:%u:%u\n",           ft.ft_hour, ft.ft_min,           ft.ft_tsec * 2);    printf("File date: %u/%u/%u\n",    ft.ft_month, ft.ft_day,    ft.ft_year+1980);    fclose(stream);    return 0; }  函数名: getgraphmode 功  能: 返回当前图形模式 用  法: int far getgraphmode(void); 程序例: #include #include #include #include int main(void) { /* request auto detection */    int gdriver = DETECT, gmode, errorcode;    int midx, midy, mode;    char numname[80], modename[80]; /* 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(); /* terminate with an error code */       exit(1);    }    midx = getmaxx() / 2;    midy = getmaxy() / 2; /* get mode number and name strings */    mode = getgraphmode();    sprintf(numname,            "%d is the current mode number.",            mode);    sprintf(modename,            "%s is the current graphics mode",            getmodename(mode)); /* display the information */    settextjustify(CENTER_TEXT, CENTER_TEXT);    outtextxy(midx, midy, numname);    outtextxy(midx, midy+2*textheight("W"),              modename); /* clean up */    getch();    closegraph();    return 0; }  函数名: getimage 功  能: 将指定区域的一个位图存到主存中 用  法: void far getimage(int left, int top, int right, int bottom,      void far *bitmap); 程序例: #include #include #include #include #include void save_screen(void far *buf[4]); void restore_screen(void far *buf[4]); int maxx, maxy; int main(void) {    int gdriver=DETECT, gmode, errorcode;    void far *ptr[4];    /* auto-detect the graphics driver and mode */    initgraph(&gdriver, &gmode, "");    errorcode = graphresult(); /* check for any errors */    if (errorcode != grOk)    {       printf("Graphics error: %s\n", grapherrormsg(errorcode));       printf("Press any key to halt:");     
/
本文档为【C语言函数】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索