//创建一个较为完善的输入函数
#include <stdio.h>
#define SIZE 80
void input_char(char *st,int n);
int main(void)
{
char names[SIZE];
input_char(names,SIZE);
puts("print the characters :");
puts(names);
return 0;
}
void input_char(char *st,int n)
{
char *ret_val;
puts("Please enter a characters you want:");
while (*(ret_val=fgets(st,n,stdin))=='\n')
{
puts("The Enter Key can't be the first char!");
puts("Input again!");
continue;
}
if (ret_val != NULL)
{
int i=0;
while (st[i] != '\n'&&st[i] != '\0')
{
i++;
}
if (st[i] == '\n')
{
st[i]='\0';
}
else//不等于换行符说明输入缓存流中有残余字符
{
while (getchar() != '\n')
{
continue;
}
}
}
return;
}