report messages

This is a discussion on report messages within the C Programming forums, part of the General Programming Boards category; Hello, C99 gcc 4.4.3 I want to report some error messages to the user of my program. I have found ...

  1. #1
    UK2
    Join Date
    Sep 2003
    Posts
    112

    report messages

    Hello,

    C99
    gcc 4.4.3

    I want to report some error messages to the user of my program. I have found that using Variadic function is the most scalable method to use, but I am not sure how to put it together, this is what I have so far.

    Many thanks for any suggestions,

    Code:
    typedef enum
    {
       DEV_FAILED, /* Device failed to open */
       EX_FAILED,   /* Cannot open library */
       HOST_INFO_ERR, /* Cannot get host information */
    } report_msg;

    Code:
    #include <stdarg.h>
    void report_error(FILE *out, const char *fmt, ...)
    {
        va_list ap;
        va_start(ap_fmt);
        vfprintf(out, fmt, ap);
        va_end(ap);
    }
    Code:
    my_error(stderr,
        "%s: Invalid range of %ld near line %d", __func__, range, __LINE__);

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I'll assume that 'my_error' was really supposed to be 'report_error'? You really only need "..." functions if your errors will have assorted numbers of arguments. Do you really need a bunch of various arguments?


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    UK2
    Join Date
    Sep 2003
    Posts
    112
    Hello,

    Yes, my_error was supposed to be report_error. I just changed the name to make it more readable.

    However, I was thinking it was better to do it this way. As I have heard many programmers use this form of error reporting. And at the moment I am just at the beginning of writing this application. So the errors will grow.

    I am just trying to get started with this, any help would be gratefull.

    Many thanks,

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    So basically you're looking to reimplement fprintf?


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    UK2
    Join Date
    Sep 2003
    Posts
    112
    I guess I am. However, I am not too sure. Do you have any samples,

    Thanks,

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I was hoping you'd sort of get the point there... why are you trying to reimplement something that already exists as a standard library function?


    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    UK2
    Join Date
    Sep 2003
    Posts
    112
    Sorry, the penny didn't drop.

    I am coming from C# and just looking for some samples that use this in C.

    Thanks,

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 05-13-2009, 01:57 PM
  2. Spy++ view messages posted/sent to a control, or from it?
    By hanhao in forum Windows Programming
    Replies: 2
    Last Post: 06-25-2007, 12:07 AM
  3. Moving Average Question
    By GCNDoug in forum C Programming
    Replies: 4
    Last Post: 04-24-2007, 12:05 AM
  4. Debug Error Really Quick Question
    By GCNDoug in forum C Programming
    Replies: 1
    Last Post: 04-23-2007, 01:05 PM
  5. Sending windows messages
    By Ideswa in forum Windows Programming
    Replies: 2
    Last Post: 03-02-2006, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21