找回密码

碧海潮声大学生网

楼主: 墙角野猫
打印 上一主题 下一主题

c语言函数大全

[复制链接]
81#
 楼主| 发表于 2006-7-12 23:27 | 只看该作者
函数名: 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'
",
ch);
return 0;
}
82#
 楼主| 发表于 2006-7-12 23:27 | 只看该作者
函数名: getcbrk
功 能: 获取Control_break设置
用 法: int getcbrk(void);
程序例:
#include
#include
int main(void)
{
if (getcbrk())
printf("Cntrl-brk flag is on
");
else
printf("Cntrl-brk flag is off
");
return 0;
}
83#
 楼主| 发表于 2006-7-12 23:28 | 只看该作者
函数名: getch
功 能: 从控制台无回显地取一个字符
用 法: int getch(void);
程序例:
#include
#include
int main(void)
{
char ch;
printf("Input a character:");
ch = getche();
printf("
You input a '%c'
", ch);
return 0;
}
84#
 楼主| 发表于 2006-7-12 23:28 | 只看该作者
函数名: 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()) != '
')
printf("%c", c);
return 0;
}
85#
 楼主| 发表于 2006-7-12 23:29 | 只看该作者
函数名: getche
功 能: 从控制台取字符(带回显)
用 法: int getche(void);
程序例:
#include
#include
int main(void)
{
char ch;
printf("Input a character:");
ch = getche();
printf("
You input a '%c'
", ch);
return 0;
}
86#
 楼主| 发表于 2006-7-12 23:30 | 只看该作者
函数名: 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
",
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;
}
87#
 楼主| 发表于 2006-7-12 23:31 | 只看该作者
函数名: 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
", curdir);
return 0;
}
88#
 楼主| 发表于 2006-7-12 23:31 | 只看该作者
函数名: getcwd
功 能: 取当前工作目录
用 法: char *getcwd(char *buf, int n);
程序例:
#include
#include
int main(void)
{
char buffer[MAXPATH];
getcwd(buffer, MAXPATH);
printf("The current directory is: %s
", buffer);
return 0;
}
89#
 楼主| 发表于 2006-7-12 23:31 | 只看该作者
函数名: getdate
功 能: 取DOS日期
用 法: void getdate(struct *dateblk);
程序例:
#include
#include
int main(void)
{
struct date d;
getdate(&d);
printf("The current year is: %d
",
d.da_year);
printf("The current day is: %d
",
d.da_day);
printf("The current month is: %d
",
d.da_mon);
return 0;
}
90#
 楼主| 发表于 2006-7-12 23:32 | 只看该作者
函数名: 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
",
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
", i,
pal->colors);
getch();
}
/* clean up */
getch();
closegraph();
return 0;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋| 碧海潮声大学生网  

Copyright © 2001-2013 Comsenz Inc.   All Rights Reserved.

Powered by Discuz! X3.2( 浙ICP备11026473号 )

快速回复 返回顶部 返回列表