开发者

How do I scan spaces into a a string?

I am trying to scan in 1-3 words from the user into a string. However, Only the first word will scan开发者_Python百科.


scanf("%s", &area ) ;

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


One possibility is to use a scan set conversion instead of a string conversion:

char buffer[256];
scanf("%255[^\n]", buffer);

Much like fgets, this reads up to the end of the line rather than stopping at the first white-space character.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜