Help with a function call

Hi, Can anyone help me figure out the problem I'm having with a function call?

I have a header file, which sets an enum:

typedef enum {INFO, WARNING, FATAL} Levels;
int log_event (Levels, char *fmt, ...);

..then the function is called this way:

log_event(INFO, "Message text");

...then the function:

int log_event(int Level, char *string_fmt) {

Every time I try to build this, I get an error, "conflicting types for log_event".

I've tried changing Level to a char, enum, Levels, and everything else I could think of, but no luck.

Can anyone shed some light on this?

-Steve :confused:

why do you have 2 different declarations for log_event() ? they have different "signature" hence the compiler is giving error. Below is a simple example that will compile.. (you can change the function definition)

typedef enum {INFO, WARNING, FATAL} Levels ;
int log_event(Levels l, char *fmt) ;

int main ( void )  {

  log_event(INFO, "Message text");

  return 0 ;
}


int log_event(Levels l, char *fmt) {
  return 2 ;
}

Thanks for the help. It had me confused there, but now I see what I was doing wrong.

Steve :slight_smile:

Actually, you are using ellipsis argument
"..."

there is no need to change the argument type

try this code, not tested

#include <stdio.h>
#include <stdarg.h>

void fun(int, char *, ...);

int main()
{
  fun(10, "%s-%s-%s", "1", "message", "2");
  return 0;
}

void fun( int a, char *p, ...)
{
  char *s;
  va_list list;
  va_start(list, p);

  memset(s, '\0', sizeof(s));
  while( *p != '\0' ) {
    s = va_arg(list, char *);
    fprintf(stderr, "%s", s);
    p++;
  }
  va_end(list);

  fprintf(stderr, "%d\n", a);
}

Hi. Thanks for the idea. I'll give this a try!

Will the fprintf function save this output to a file?

-Steve

The above line uses stderr to give the output

use a file handle that was opened;
in the below fprintf to save the information in to a file

fprintf (fp, <to be saved>);

Thanks for the help!

-Steve