1.11M Members

%n Conversion Specifier

 
0
 

I've been trying to read all I can about the %n conversion specifier, but I'm having trouble with it. In the following code, I generate ten random numbers between 1 - 1000 and save each to an element of the array. I need to use %n to keep a running total of the characters, but can't get it to work. Any idea how to do this?

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()
{
  int x;
  int num[10] = {0};
  int count = 0;
  int total = 0;
  int _set_printf_count_output = 2;
  srand(time(NULL));

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

          printf( "Value:%d\tTotal Characters:%d\n", x, total);
        }

return 0;
}
 
0
 

Well Nevermind ... I got it figured out just after posting this. Sorry about that. Sometimes it takes posting the question before the answer comes to mind ...

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article