c语言conio.h和stdio.h函数

版权声明:欢迎转载请注明转自方辰昱的博客https://blog.csdn.net/viafcccy https://blog.csdn.net/viafcccy/article/details/84328176

conio是Console Input/Output(控制台输入输出)的简写,其中定义了通过控制台进行数据输入和数据输出的函数,主要是一些用户通过按键盘产生的对应操作,比如getch()函数等等。 

来源百度百科 https://baike.baidu.com/item/conio.h/2912801?fr=aladdin

getch()与getchar()的主要区别是

getch()不用回车即可获得字符enter

getchar()需要按下enter才会获取

getch()一次只能读取一个字符

键盘的上下左右都是两个字符

ascii码表对应的上下左右

上72

下80

左75

右77

函数名: getch
功  能: 从控制台无回显地取一个字符
用  法: int getch(void);
程序例:

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

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 <stdio.h>

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;
}

sprintf

函数名: sprintf
功  能: 送格式化输出到字符串中
用  法: int sprintf(char *string, char *farmat [,argument,...]);
程序例:

#include <stdio.h>
#include <math.h>

int main(void)
{
   char buffer[80];

   sprintf(buffer, "An approximation of Pi is %f\n", M_PI);
   puts(buffer);
   return 0;
}
/*将整形变量转化为字符串格式*/

猜你喜欢

转载自blog.csdn.net/viafcccy/article/details/84328176