I wrote an Ansi C# code that finds the smallest number in a several unknown function calls.
You can see the code, it is very clear. just need help with how to make the program to not ignore always the first number in the list of each argument list... and another, how to handle with call like:
lowest_ever ( -1);
The range of numbers is between 0 to +100 ONLY ! and every call to function must end with -1 (those are the roles....).
My tryout:
#include <stdarg.h>
#include <stdio.h>
int lowest_ever (int frst,...)
{
va_list mylist;
static int lowest_num=101;
static int next_num;
va_start (mylist, frst); /*Initialize the argument list*/
next_num= va_arg(mylist, int);
while (next_num!=-1)
{
if (next_num <lowest_num)
lowest_num= next_num;
next_num = va_arg(mylist, int);
}
va_end (mylist); /*Clean up */
return lowest_num;
}
int
main (void)
{
/*This call prints 5*/
printf ("%d\n", lowest_ever (5, 78, 90, 20, -1));
/*This call prints 2*/
printf ("%d\n", lowest_ever (70, 40, 2, -1));
/*This call prints 2*/
printf ("%d\n", lowest_ever (40, 30, -1));
return 0;
}
Thanks !!