gpt4 book ai didi

c - %n 如何处理变量

转载 作者:太空宇宙 更新时间:2023-11-04 08:28:16 24 4
gpt4 key购买 nike

<分区>

所以我环顾四周,发现一般情况下关于 %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);
}
}

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