How do I scan spaces into a a string?

前端 未结 2 1987
庸人自扰
庸人自扰 2021-01-22 17:18

I am trying to scan in 1-3 words from the user into a string. However, Only the first word will scan.

2条回答
  •  北恋
    北恋 (楼主)
    2021-01-22 17:38

    scanf("%s", &area ) ;
    

    scanf stops reading from the stream when a space is encountered. You need to use getline instead.

提交回复
热议问题