用fgetc试试呢。例如:
#include
#include
int main(void)
{
int c;
int index = 0;
char s[5000];
while (1) {
c=fgetc(stdin);
if (c == EOF)
break;
if (c == '\n')
break;
s[index++] = c;
if (index >= 5000)
break;
}
printf("%s\n", s);
return 0;
}
那就使用两个数组,然后用函数strcat把他们拼接起来。