为什么我的程序只打印出所有其他字符?C

Art*_*hur 0 c printf linked-list

我创建了一个程序,以相反的顺序打印出一个字符串(以'.'结尾).程序获取每个char并以相反的顺序将其存储在链接列表中,然后在main函数中打印出链接列表.它工作,但它打印出所有其他char.

int main (void)
{
    printf("Enter text: ");
    char text;
    textE *nexttext = NULL;
    while(getchar() != '\n')
    {
        text = getchar();
        nexttext = insertchar(nexttext, text);
    }
 }
Run Code Online (Sandbox Code Playgroud)

bry*_*cem 5

getchar()while环和getchar()text = getchar();都采取的性格缓冲区.你只看到输出中的每个字符,因为你在输入上丢失了所有奇怪的字符.