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;
}

Edited by WaltP: Added CODE Tags

1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by TimCereja
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 ...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.