且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 scanf() 扫描包含空格的字符串?

更新时间:2023-02-26 11:03:05

而不是告诉你不要使用 scanf() 的答案,你可以否定扫描集 scanf() 选项:

Rather than the answers that tell you not to use scanf(), you can just the the Negated scanset option of scanf():

scanf("%99[^
]",comment); // This will read into the string: comment 
                           // everything from the next 99 characters up until 
                           // it gets a newline