程序代码:#include <stdio.h>
#include <stdlib.h>
// 代替 fflush
// #define LINEEND while(getchar() != '\n')
#define LINEEND do{int ch; while((ch=getchar() != '\n') && ch != EOF)}while(0)
// 自定义函数解决
// myGetLine(clientName, sizeof clientName);
int myGetLine(char *str, int size)
{
int ch, i;
if (!str || size < 1)
return 0;
for (--size, i=0; (ch=getchar() != '\n') && ch != EOF && i < size; ++i)
str[i] = ch;
str[i] = '\0';
while(ch != '\n' && ch != EOF)
ch = getchar();
return i;
}
int main(void)
{
char clientName[21];
char input[1024];
printf("please input your name,note:your name lenth not over 20 byte\n");
scanf("%s",clientName);
fflush(stdin); // LINEEND;
while(1)
{
fgets(input, sizeof(input), stdin);
fflush(stdin); // LINEEND;
break;
}
puts(clientName);
puts(input);
return 0;
}[ 本帖最后由 cosdos 于 2012-4-20 18:30 编辑 ]

—>〉Sun〈<—







