gpt4 book ai didi

c - 这是如何使用scanf接受多字串的?

转载 作者:行者123 更新时间:2023-12-04 06:34:59 26 4
gpt4 key购买 nike

printf("enter the string");
scanf("%[^\t\n]s",str);

//abv 代码如何在不使用 get 且仅使用 scanf 的情况下接受多字串

最佳答案

[ Matches a nonempty sequence of characters from the specified set of accepted characters; the next pointer must be a pointer to char, and there must be enough room for all the characters in the string, plus a terminating null byte. The usual skip of leading white space is suppressed. The string is to be made up of characters in (or not in) a particular set; the set is defined by the characters between the open bracket [ character and a close bracket ] character. The set excludes those characters if the first character after the open bracket is a circumflex (^).

...

The string ends with the appearance of a character not in the (or, with a circumflex, in) set or when the field width runs out.



(Linux scanf(3) 联机帮助页。)

所以 scanf读取到第一个不是制表符 ( \t ) 或换行符 ( \n ) 的字符。它确实读取空格。

关于c - 这是如何使用scanf接受多字串的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4977467/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com