Thread: including optional parameters in function

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    2

    Question including optional parameters in function

    I want to include optional parameters in my function but I don't know the correct syntax, can anyone help me out?


    thanks

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    I take it by optional parameters you mean the same effect as printf? You can make use of the macros defined in stdarg.h.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <stdarg.h>
    
    void va_Error ( const char *fmt, va_list args )
    {
      vfprintf ( stderr, fmt, args );
    }
    
    void Error ( const char *fmt, ... )
    {
      va_list args;
    
      va_start ( args, fmt );
      va_Error ( fmt, args );
      va_end ( args );
    
      exit ( EXIT_FAILURE );
    }
    
    int main ( void )
    {
      Error ( "Fatal error %d : %s\n", 1, "Stupid user" );
    
      return EXIT_SUCCESS;
    }
    -Prelude
    My best code is written with the delete key.

  3. #3
    ~- Y u n a -~ beely's Avatar
    Join Date
    Dec 2001
    Posts
    291
    what mean of "vfprintf " ?

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >what mean of "vfprintf " ?
    I was expecting this one.

    http://www.rt.com/man/vfprintf.3.html

    -Prelude
    My best code is written with the delete key.

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    2

    Talking Very nice !

    Thanks, that's what I was lookn' for

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  2. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM