Input and output of getchar(), putchar(), gets(), puts(), printf(), scanf()

Use getchar(), putchar(), gets(), puts(), printf(), scanf() to complete OK input and output.

getchar()、putchar()

#include <stdio.h>
int main ()
{
    
    
	char c1 , c2 ;
	printf("请输入字符串:\n");
	c1 = getchar();
	c2 = getchar();
	printf("您输入的字符串为:\n");
	putchar(c1);
	putchar(c2);
	putchar('\n');
	return 0;
}

gets()、puts()

#include <stdio.h>
int main ()
{
    
    
	char s[10];
	printf("请输入字符串:\n");
	gets(s);
	printf("您输入的字符串为:\n");
	puts(s);//puts完毕会自动换行
	return 0;
}

printf()、scanf()

#include <stdio.h>
int main ()
{
    
    
	char c3 , c4 ;
	printf("请输入字符串:\n");
	scanf ("%c%c" , &c3,&c4);
	printf("您输入的字符串为:\n%c%c\n", c3 , c4 );
	return 0;
}

The results are shown in the figure below
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_51070490/article/details/112641883