%n Conversion Specifier

I've been having trouble using %n. In the following program, I've written something that randomly generates ten integers between 1 - 1000 and saves each to an element of the array. I need to output each individual value and a running total of the number of characters of the numbers (ie: 1 = 1, 10 = 2, 100 = 3). I know that %n is used to do this, but cannot seem to get it to work. Any ideas about this?


int main()
int x;
int num[10] = {0};
int count = 0;
int total = 0;
int *ptr
int _set_printf_count_output = 2;

for(count = 1; count <= 10; count++)
x = 1 + (rand()%1000);
num[count] = x;

printf( "Value:%d Total Characters:%d
", x, total);

return 0;


  • Well Nevermind ... I got it figured out just after posting this. Sorry for the bother.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion