问问题
1036 次
1 回答
2
如果您fgets
习惯于读取行,并且您担心您可能没有读取整行,请记住,如果fgets
读取整行,则换行符应该是输入缓冲区中的最后一个字符。
例子:
char smallBuffer[10];
while (fgets(smallBuffer, sizeof(smallBuffer), stdin) != NULL)
{
if (strlen(smallBuffer) > 0)
{
// Check if we got the whole line
if (smallBuffer[strlen(smallBuffer) - 1] == '\n')
{
// Yes, we got the whole line
}
else
{
// Whole line not read, there is still "excess" input
}
}
}
于 2014-08-27T12:28:25.233 回答