因此,我环顾四周,发现%n一般信息很少,没有关于如何将它与变量一起使用的信息。%n如何与变量一起工作
据我可以告诉我使用的代码应该工作,但我不知道它不是什么。我遇到的特定行是:
printf("%d %n", num[x], &c);
以下是整个代码。
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
//seed rand, declare arrays, declare variables
srand(time(NULL));
int num[10];
int c = 0;
int total = 0;
int x;
printf("%s%14s%20s\n", "Value", "Characters", "Total Characters");
//Loads the num array with random numbers.
for(x = 1; x < 10; x++)
{
num[x] = 1 + rand() % 1000;
}
for (x = 1; x < 10; x++)
{
printf("%d %n", num[x], &c);
printf("%14d", c);
total = total + c;
printf("%20d\n", total);
}
}
[这里](http://stackoverflow.com/问题/ 3401156 /这是n-format-specifier-in-c的用法) – 2015-04-04 18:03:30
很少的信息?在这里:https://msdn.microsoft.com/en-us/library/hf4y5e3w.aspx – 2015-04-04 18:08:42
btw:在rand()的输出上计算_any_类型将统计减少它的随机性,您可以有效地生成伪随机数这是可预测的。 – specializt 2015-04-04 19:56:21