How to Count Variable Numbers of Arguments in C? Last Updated : 28 May, 2017 Comments Improve Suggest changes Like Article Like Report C supports variable numbers of arguments. But there is no language provided way for finding out total number of arguments passed. User has to handle this in one of the following ways: 1) By passing first argument as count of arguments. 2) By passing last argument as NULL (or 0). 3) Using some printf (or scanf) like mechanism where first argument has placeholders for rest of the arguments. Following is an example that uses first argument arg_count to hold count of other arguments. C #include <stdarg.h> #include <stdio.h> // this function returns minimum of integer numbers passed. First // argument is count of numbers. int min(int arg_count, ...) { int i; int min, a; // va_list is a type to hold information about variable arguments va_list ap; // va_start must be called before accessing variable argument list va_start(ap, arg_count); // Now arguments can be accessed one by one using va_arg macro // Initialize min as first argument in list min = va_arg(ap, int); // traverse rest of the arguments to find out minimum for(i = 2; i <= arg_count; i++) { if((a = va_arg(ap, int)) < min) min = a; } //va_end should be executed before the function returns whenever // va_start has been previously used in that function va_end(ap); return min; } int main() { int count = 5; // Find minimum of 5 numbers: (12, 67, 6, 7, 100) printf("Minimum value is %d", min(count, 12, 67, 6, 7, 100)); getchar(); return 0; } Output: Minimum value is 6 Comment More infoAdvertise with us Next Article How to Count Variable Numbers of Arguments in C? kartik Follow Improve Article Tags : C Language C-Functions Similar Reads Variable Length Argument in C Variable length argument is a feature that allows a function to receive any number of arguments. There are situations where we want a function to handle variable number of arguments according to requirement. 1) Sum of given numbers. 2) Minimum of given numbers. and many more. Variable number of argu 3 min read getopt() function in C to parse command line arguments The getopt() function is a builtin function in C and is used to parse command line arguments. Syntax: getopt(int argc, char *const argv[], const char *optstring) optstring is simply a list of characters, each representing a single character option. Return Value: The getopt() function returns differe 2 min read How to count set bits in a floating point number in C? Given a floating point number, write a function to count set bits in its binary representation. For example, floating point representation of 0.15625 has 6 set bits (See this). A typical C compiler uses single precision floating point format. We can use the idea discussed here. The idea is to take a 2 min read C Program to count number of lines in a file C /* C Program to count the Number of Lines in a Text File */ #include <stdio.h> #define MAX_FILE_NAME 100 int main() { FILE *fp; int count = 0; // Line counter (result) char filename[MAX_FILE_NAME]; char c; // To store a character read from file // Get file name from user. The file should be 1 min read C Program to count the Number of Characters in a File Counting the number of characters is important because almost all the text boxes that rely on user input have certain limitations on the number of characters that can be inserted. For example, the character limit on a Facebook post is 63,206 characters. Whereas, for a tweet on Twitter the character 2 min read Like