///////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <string.h>
#define STR_BUFFSIZE 5
void myfflush(FILE *stream)
{
char buffer[STR_BUFFSIZE];
while( fgets(buffer, STR_BUFFSIZE, stdin) != NULL )
if(buffer[strlen(buffer)-1] == '\n' )
break;
return;
}
main()
{
int num = 1;
char buff[STR_BUFFSIZE];
char str[STR_BUFFSIZE];
memset(buff,0x0,sizeof(buff));
memset(str,0x0,sizeof(str));
printf("请输入第 %d 个记录然后按回车(如果输入完毕,则直接以回车结束):\n", num);
printf("记录:");
if(fgets(buff, STR_BUFFSIZE, stdin) == NULL)
{
perror("Input error, abort!\n");
exit(1);
}
myfflush(stdin);
while(strcmp(buff,"\n") != 0) //判断是否回车
{
sscanf(buff,"%s",str);
printf("Input string is: %s\n",str);
memset(buff,0x0,sizeof(buff));
memset(str,0x0,sizeof(str));
printf("请输入第 %d 个记录然后按回车(如果输入完毕,则直接以回车结束):\n", ++num);
printf("记录:");
if(fgets(buff, STR_BUFFSIZE, stdin) == NULL)
{
perror("Input error, abort!\n");
exit(1);
}
myfflush(stdin);
}
printf("End.\n");
}