please dont rip this site

Language Ccpp Cref Examples Var_func.c

/ ************************************************************************
 *
 * Purpose: Program to demonstrate functions that have a variable
 *	    number of parameters.
 * Author:  M J Leslie.
 * Date:    28-Mar-94
 *
 ************************************************************************/

#include <stdio.h>
#include <stdarg.h>			/* va_list, va_arg, va_end	*/

int set(char *item, int num, ...);	/* Declare the function.        */

/************************************************************************/

main()
{
    char *item="pear";

    int   Ret;
     
    Ret = set (item,4, "apple", "pear", "banana", "grape");
     
    if (Ret)
    {
        printf ("%s found\n", item);
    }
    else
    {
        printf("%s not found\n", item);
    }
}

/************************************************************************/

int set(char *item, int num, ...)
{
    va_list ap;				/* define 'ap' It acts as a
					 * pointer to the undefined 
					 * variables.			*/
    int Ret=0;
    int Inc=0;                          /* Assume the worst.            */
    va_start(ap, num);			/* seed 'ap'			*/

    do
    {
        if ( item == va_arg(ap, char *))
        {
            Ret = 1;
        }
    } while ( Ret==0 && ++Inc < num);

    va_end(ap);				/* tidy up.			*/
    return (Ret);
}


file: /Techref/language/ccpp/Cref/EXAMPLES/var_func.c, 1KB, , updated: 1998/4/4 22:21, local time: 2024/12/4 20:04,
TOP NEW HELP FIND: 
3.133.120.143:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://sxlist.com/TECHREF/language/ccpp/Cref/EXAMPLES/var_func.c"> language ccpp Cref EXAMPLES var_func</A>

Did you find what you needed?

 

Welcome to sxlist.com!


Site supported by
sales, advertizing,
& kind contributors
just like you!

Please don't rip/copy
(here's why

Copies of the site on CD
are available at minimal cost.
 

Welcome to sxlist.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .