How do you read scanf until EOF in C?

前端 未结 7 2137
暗喜
暗喜 2020-12-03 02:56

I have this but once it reaches the supposed EOF it just repeats the loop and scanf again.

int main(void)
{
        char words[16];

        while(scanf(\"%1         


        
7条回答
  •  醉酒成梦
    2020-12-03 03:35

    I guess best way to do this is ...

    int main()
    {
        char str[100];
        scanf("[^EOF]",str);
        printf("%s",str);
        return 0;     
    }
    

提交回复
热议问题