putchar
函数名: putchar
功 能: 在stdout上输出字符
用 法: int putchar(int ch);
程序例:
#include <stdio.h>
/* define some box-drawing characters */
#define LEFT_TOP 0xDA
#define RIGHT_TOP 0xBF
#define HORIZ 0xC4
#define VERT 0xB3
#define LEFT_BOT 0xC0
#define RIGHT_BOT 0xD9
int main(void)
{
char i, j;
/* draw the top of the box */
putchar(LEFT_TOP);
for (i=0; i<10; i++)
putchar(HORIZ);
putchar(RIGHT_TOP);
putchar('
');
/* draw the middle */
for (i=0; i<4; i++)
putchar(VERT);
for (j=0; j<10; j++)
putchar(' ');
putchar(VERT);
putchar('
');
/* draw the bottom */
putchar(LEFT_BOT);
for (i=0; i<10; i++)
putchar(HORIZ);
putchar(RIGHT_BOT);
putchar('
');
return 0;
}
putchar函数(字符输出函数)的作用是向终端输出一个字符。其一般形式为 putchar(c)
例:
#include<stdio.h>
int main(void)
{
char a,b,c;
a='T',b='M',c=‘D’;
putchar(a);putchar(b);putchar(c);putchar(
);
putchar(a);putchar('
');putchar(b);putchar('
');putchar(c);putchar('
');return 0;
}
输出结果为:
TMD
T
M
D