-1

So as the title says in my C Program i get as command line inputs as usual argc and argv. However upon further inspecting, i realized that my incoming argc is a completely random number.

Here is the start of my program where i want to know the value of argc.

void debug(char *format, ...) {
    if(DEBUG_MODE!=0) return;
    va_list arg;

    va_start (arg, format);
    (void) fprintf (stdout, format, arg);
    va_end (arg);
}

int main(int argc, char *argv[]) {
    debug("ARGC %i\n", argc);

Where debug() is just a better print method. So when i start my program with:

./server

I just get as a result:

 ARGC -1786798448

So i really dont understand this.

Levent Dag
  • 132
  • 7

1 Answers1

1

A variable of type va_list isn't something you can pass to fprintf().

Try: (void) vfprintf (stdout, format, arg);

See vprintf

Ed Heal
  • 57,599
  • 16
  • 82
  • 120
Michael Burr
  • 321,763
  • 49
  • 514
  • 739