我一直在扯出我的头发,试图找出为什么它不会打印出测试消息并输入while
循环。有任何想法吗?为什么不能进入while循环?
void getInput(char * string)
{
char * tempString;
int maxLength = 1026; // Accounts for NULL and \n.
tempString = malloc(maxLength * sizeof(char));
fgets(tempString, maxLength, stdin);
size_t len = strlen(tempString);
while ((int)len > maxLength)
{
printf("Test");
if (tempString[len-1] == '\n')
{
tempString[len-1] = '\0';
len = strlen(tempString);
} // if
} // while
因为len不大于maxLength。 –