Hi
I am looking for a function which should have the same behaviour of in-build printf function.
I tried following code which i got it thru google but it ends up with compilation error:
Code:
#include <stdio.h>
#include <stdarg.h> /* va_list, va_arg, va_end */
int set(char *item, int, num, ...);
main()
{
char *item="pear";
(set (item,4, "apple", "pear", "banana", "grape") )
? printf ("%s found\n", item) : 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 ok=0;
int inc=0;
va_start(ap, num); /* seed 'ap' */
do {
if ( item == va_arg(ap, char *)) ok=1;
} while ( ok==0 && ++inc < num);
va_end(ap); /* tidy up. */
return (ok);
}
And i get following errors:
TestArgs2.c:14: error: syntax error before "num"
TestArgs2.c:30: error: conflicting types for `set'
TestArgs2.c:30: error: a parameter list with an ellipsis can't match an empty parameter name list declaration
TestArgs2.c:14: error: previous declaration of `set'
Any help is highly appreciated
Thank you all
Ravi