允许 NULL arg 到 sscanf? [英] NULL arg allowed to sscanf?
问题描述
在调用 sscanf
时,是否允许 NULL
指针作为存储结果的字符串?我在任何文档中都没有找到任何关于它的信息,但它似乎工作正常.与 scanf
相同.
Is a NULL
pointer allowed as the string to store result in in a call to sscanf
? I don't find anything about it in any documentation but it seems to be working fine. Same thing with scanf
.
示例:
int main(int arc, char* argv[])
{
char* s = NULL;
sscanf("Privjet mir!", "%s", s);
printf("s: %s\n", s);
return 0;
}
输出:s:(null)
推荐答案
否:
匹配非空白序列人物;下一个指针必须是一个指向字符数组的指针足够长的时间来保存输入序列和终止空字符('\0'),它是自动添加的.输入字符串在空格处停止或在最大字段宽度,以先发生者为准.
Matches a sequence of non-white-space characters; the next pointer must be a pointer to character array that is long enough to hold the input sequence and the terminating null character ('\0'), which is added automatically. The input string stops at white space or at the maximum field width, whichever occurs first.
(http://linux.die.net/man/3/sscanf)
这篇关于允许 NULL arg 到 sscanf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!