C语言-输入一个长度5000的字符型数组

2025-05-09 03:15:05
推荐回答(2个)
回答1:

用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;
}

回答2:

那就使用两个数组,然后用函数strcat把他们拼接起来。