including optional parameters in function

This is a discussion on including optional parameters in function within the C Programming forums, part of the General Programming Boards category; I want to include optional parameters in my function but I don't know the correct syntax, can anyone help me ...

  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,796
    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,796
    >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-17-2006, 12:35 AM
  2. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 09:56 AM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 06:45 AM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM

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