int x;
printf("hello %n World\n", &x);
printf("%d\n", x);
最佳答案
它对 printf()
不是很有用,但对 sscanf()
非常有用,尤其是当您在多次迭代中解析字符串时。 fscanf()
和 scanf()
会根据输入读取的数量自动推进其内部指针,但 sscanf()
不会。例如:
char stringToParse[256];
...
char *curPosInString = stringToParse; // start parsing at the beginning
int bytesRead;
while(needsParsing())
{
sscanf(curPosInString, "(format string)%n", ..., &bytesRead); // check the return value here
curPosInString += bytesRead; // Advance read pointer
...
}
关于c - printf/scanf 系列中的格式 %n 是否有任何实际应用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/353614/