conio.h这个头文件是干什么的?

yga 2003-01-08 05:15:48
有人能告诉我里面还有一些什么函数,都是干什么的
还有stdlib.h杂项说明里面都有什么函数
...全文
3387 16 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangyangcheng 2003-04-17
  • 打赏
  • 举报
回复
TO:holydiablo
您講的就兩支程序﹐你用什么compiler試過?
wangyangcheng 2003-04-17
  • 打赏
  • 举报
回复
Visual C++5.0 compiler里面的conio.h已經不去持上面所說的這些函數了﹐哪又怎么實現你上面所講的這些功能呢?
哪位高手知道嗎?
alan118 2003-01-09
  • 打赏
  • 举报
回复
up
sinusoid 2003-01-09
  • 打赏
  • 举报
回复
holydiablo(鱼头) 这是哪本的书的例子呀,不错。

c中常包含conio.h完成清屏工作。

#include<conio.h>
main()
{
clrscr();
}
holydiablo 2003-01-09
  • 打赏
  • 举报
回复
C语言中,图形函数大致可分为两类:字符模式函数和图形模式函数。本节我们练习使用字符模式函数。
使用字符模式函数应该在程序中联入conio.h头部文件。
下面是一些函数的作用
1) void clreol(); 从光标处删除到本行末
2) void delline(); 清除本行内容,下面内容上提一行
delline();函数实际上还起到了向上卷屏的作用。
3) void insline(); 在光标所在行插入一空行,原来该行及以
下各行皆向下移一行
4) int wherex(); 返回当前光标的x(行)坐标
5) int wherey(); 返回当前光标的y(列)坐标
6) void highvideo(); 字符输出用高亮度字符
7) void lowvideo(); 字符输出用低亮度字符
8) void normvideo(); 字符输出用普通亮度字符
在以上的各函数中皆不带参数,当然也可以写成括号中有void的形式:
void wherex(void); 还可以写成 wherex();
清屏、清行、向后删行、插行的操作真有些CCED、WPS等编辑软件的风格,就是在你平时的屏幕设计中也用少不了。返回坐标的函数则给你的设计提供每一个环节的光标坐标值。有利于你前后响应。字
符亮度的改变则会让你的字符显示出层次感,怎么样,赶快试试吧:
/* No32.c*/
# include "stdio.h"
# include "conio.h"
main()
{ clrscr();
gotoxy(10,1);
cprintf("甜密密,");
highvideo(); /*高亮度显示*/
cprintf("\r\n 你笑得甜密密,");
lowvideo(); /*低亮度显示*/
cprintf("\r\n 好象花儿开在春风里,");
normvideo(); /*普通亮度显示*/
gotoxy(10,4); cprintf("开在春风里");
cprintf("\r\n 在哪里,在哪里见过你?");
printf("\r\n 你的笑容这样熟悉。");
gotoxy(10,20);printf("任意键删去光标后的内容");
gotoxy(18,3); getch();
gotoxy(18,3);
clreol(); /*删去光标后字符*/
gotoxy(10,20);printf("任意键删去本行的内容 ");
gotoxy(18,3); getch();
delline(); /*删去本行*/
gotoxy(10,20);printf("任意键在本行插一空行 ");
gotoxy(18,3); getch();
insline(); /*插入一空行*/
gotoxy(1,7);
}
应该注意的是,要发挥本节所讲的函数的作用,在显示时不能使printf函数,应使用cprintf函数。它的使用方法和printf的完全一样,只不过后面的cprintf能发挥亮度设置和颜色设置的作用。前者
printf函数只有一种颜色和单一的亮度。
在cprintf函数中,“\n”的作用不再是既回到行首又换行,它只起一个换行的作用,所以要把内容在行首显示必须再加一个“\r”
上面的程序不是一真正对大家有用的程序,只是用来说明一个刚刚学到的几个函数的作用。在conio.h中还有一些字符型函数,它们都是带参数的。
9) void textcolor(颜色); 定义显示字符颜色
10) void textbackground(颜色); 定义背景颜色
下面是颜色数字和颜色对照表
BLACK 0 黑 DARKGRAY 8 深灰
BLUE 1 兰 LIGHTBLUE 9 淡兰
GREEN 2 绿 LIGHTGREEN 10 淡绿
CYAN 3 青 LIGHTCYAN 11 淡青
RED 4 红 LIGHTRED 12 淡红
MAGENTA 5 洋红 LIGHTMAGENTA 13 淡洋红
BROWN 6 棕 YELLOW 14 黄
LIGHTGRAY 7 淡灰 WHILT 15 白
背景颜色值只能是0-7共8个数字或其对应的英文大写单词。而前景(即字符)的颜色可以是0-15共16种颜色或其对应的英文大写单词。当你定义的前景和背景相同时,屏幕上看不到输出的内容。
textcolor(4); 和 textcolor(RED); 效果是相同的。
设置屏幕颜色还可以使用
11) void textattr(前景颜色+(背景颜色));
但这里的背景颜色要有“<<4”。如白底红字,就是:
textattr(RED+(WHITE<<4));
12) int gettext(左上角x,左上角y,右下角x,右下角y,内存指针);
把定义的长方形区域内的内容存在内存中
13) int puttext(左上角x,左上角y,右下角x,右下角y,内存指针);
把内存中存好的内容显示在新定义的矩形块内
这里的内存指针也可用字符形数组来代替。需要注意的是内存大小应该是所存内容的“行数*列数*2”。比如把第3行第5列到第6行第75列的数据存到内存中,可以用下面的片段:
char buffer[4*70*2];
gettext(5,3,75,6,buffer);
然后你就可以用puttext函数来显示它了。
14) void movetext(左上角x,左上角y,右下角x,右下角y,
新左上角x,新左上角y);
把矩形块移到新左上角(x,y)决定的地方
15) void window(左上角x,左上角y,右下角x,右下角y);
定义一个窗口,大小就是上面参数决定的长方形
利用这一函数,你可以在屏幕上任何一个地方开辟一个窗口,并在上面显示需要的内容。这丝毫不影响屏幕其它地方的内容。当你定义了窗口后,你只能操作该窗口,gotoxy(),wherex(),wherey(),
clrscr()等等函数所表示的都是你定义窗口中的情况。实际上这就为我们的操作带来了方便,你想操作哪儿,就定义哪儿,想回到平时状态的屏幕,就定义一个最大的窗口,window(1,1,80,25);就复原了。
No.33号例子是利用puttext和gettext函数以及颜色定义来模仿CCED和WPS的菜单显示。但这个小程序没有可移动的光条,也没有菜单中内容的相应执行程序,只是演示一下屏幕的保存和释放而已。
/* No33.c */
#include "conio.h"
#include "stdio.h"
main()
{ int i=1,j,ch;
char buffer[6*50*2]; /*开辟内存空间的大小*/
clrscr();
textcolor(0); /*定义字符颜色*/
textbackground(7); /*定义背景颜色*/
gotoxy(1,1);
cprintf(" 功能1 功能2 功能3 ");
textbackground(0);
textcolor(14);
gotoxy(1,2);
cprintf("What's your name? 你叫什么名字");
cprintf("\n\rMy name is Wang Dong. 我叫王东.");
cprintf("\n\rHow old are are you? 你多大了 . ");
cprintf("\n\rI'm thirty-four. 我四十四了");
cprintf("\n\r\n\rThis is Lesson One. 这是第一课");
while(1)
{ j=i;
textcolor(0);
textbackground(7);
if(i==1)
{ gettext(1,2,13,5,buffer);
gotoxy(2,2); cprintf("│第一课│");
gotoxy(2,3); cprintf("│第二课│");
gotoxy(2,4); cprintf("│第三课│");
gotoxy(2,5); cprintf("└───┘");
}
if(i==2)
{ gettext(13,2,25,5,buffer);
gotoxy(14,2); cprintf("│菜单一│");
gotoxy(14,3); cprintf("│菜单二│");
gotoxy(14,4); cprintf("│菜单三│");
gotoxy(14,5); cprintf("└───┘");
}
if(i==3)
{ gettext(25,2,37,5,buffer);
gotoxy(26,2); cprintf("│说明A │");
gotoxy(26,3); cprintf("│说明B │");
gotoxy(26,4); cprintf("│说明C │");
gotoxy(26,5); cprintf("└───┘");
}
textcolor(14);
gotoxy(10,20);printf("→向右移动 ←向左移动 Esc 退出");
ch=getch();
if((ch==75)&&(i==1)) /*菜单个数的判断*/
{ i=3; ch=0;}
if((ch==77)&&(i==3)) /*ASCII码 77是右箭头*/
{ i=1; ch=0;}
if((ch==75)&&(i>1)) /*ASCII码 75是左箭头*/
i--;
if((ch==77)&&(i<3))
i++;
if(ch==27)
break;
puttext(j*12-11,2,j*12+1,5,buffer);
}
}
yga 2003-01-09
  • 打赏
  • 举报
回复
为什么不用汉语呢????????????????????????

我可是个初学者!!!!!哎5555555555555555555555555
qing_li73 2003-01-08
  • 打赏
  • 举报
回复
So many relative contents in MSDN, find by yourself :)
qing_li73 2003-01-08
  • 打赏
  • 举报
回复
_cgets
Gets a character string from the console.

char *_cgets( char *buffer );

Routine Required Header Compatibility
_cgets <conio.h> Win 95, Win NT


For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version


Return Value

_cgets returns a pointer to the start of the string, at buffer[2]. There is no error return.

Parameter

buffer

Storage location for data

Remarks

The _cgets function reads a string of characters from the console and stores the string and its length in the location pointed to by buffer. The buffer parameter must be a pointer to a character array. The first element of the array, buffer[0], must contain the maximum length (in characters) of the string to be read. The array must contain enough elements to hold the string, a terminating null character ('\0'), and two additional bytes. The function reads characters until a carriage-return – linefeed (CR-LF) combination or the specified number of characters is read. The string is stored starting at buffer[2]. If the function reads a CR-LF, it stores the null character ('\0'). _cgets then stores the actual length of the string in the second array element, buffer [1]. Because all editing keys are active when _cgets is called, pressing F3 repeats the last entry.

Example

/* CGETS.C: This program creates a buffer and initializes
* the first byte to the size of the buffer: 2. Next, the
* program accepts an input string using _cgets and displays
* the size and text of that string.
*/

#include <conio.h>
#include <stdio.h>

void main( void )
{
char buffer[82] = { 80 }; /* Maximum characters in 1st byte */
char *result;

printf( "Input line of text, followed by carriage return:\n");
result = _cgets( buffer ); /* Input a line of text */
printf( "\nLine length = %d\nText = %s\n", buffer[1], result );
}


Output

Input line of text, followed by carriage return:
This is a line of text

Line length = 22
Text = This is a line of text.



Console and Port I/O Routines

See Also _getch
qing_li73 2003-01-08
  • 打赏
  • 举报
回复
Console and Port I/O
These routines read and write on your console or on the specified port. The console I/O routines are not compatible with stream I/O or low-level I/O library routines. The console or port does not have to be opened or closed before I/O is performed, so there are no open or close routines in this category. In Windows NT and Windows 95, the output from these functions is always directed to the console and cannot be redirected.

Console and Port I/O Routines

Routine Use
_cgets Read string from console
_cprintf Write formatted data to console
_cputs Write string to console
_cscanf Read formatted data from console
_getch Read character from console
_getche Read character from console and echo it
_inp Read one byte from specified I/O port
_inpd Read double word from specified I/O port
_inpw Read 2-byte word from specified I/O port
_kbhit Check for keystroke at console; use before attempting to read from console
_outp Write one byte to specified I/O port
_outpd Write double word to specified I/O port
_outpw Write word to specified I/O port
_putch Write character to console
_ungetch “Unget” last character read from console so it becomes next character read
yga 2003-01-08
  • 打赏
  • 举报
回复
我们课本上没有,能不能说的详细点。
谢谢!
PaulZhao 2003-01-08
  • 打赏
  • 举报
回复
And one more thing conio.h is not only in TC2.0 ,BC++、VC++、BCB have this file in the INCLUDE directory .
PaulZhao 2003-01-08
  • 打赏
  • 举报
回复
/* I/O function,use it for a pause in order to see the result after execution. use getch() to pause ,and conio.h is need by getch() function */

#include <stdio.h>
#include <conio.h>

void main()
{
printf("Hello,world");
getch(); /* pause until you press a key */
}


  • 打赏
  • 举报
回复
con是控制台的缩写,io是输入、输出的缩写。
故,这个库函数是进行输入、输出的。
ckc 2003-01-08
  • 打赏
  • 举报
回复
conio.h好象是dos下用的一些函数
web_spider 2003-01-08
  • 打赏
  • 举报
回复
vc中的说明:
This include file contains the function declarations for
the MS C V2.03 compatible console I/O routines.
lkcowboy 2003-01-08
  • 打赏
  • 举报
回复
conio.h是TC特有的,用于输入输出图形方面
查查书

70,024

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧