In this project, I learned about using variadic functions with the va_start,
va_arg, and va_end macros as well as why and how to use the const type qualifier in C.
- variadic_functions.h: Header file containing definitions and prototypes for all types and functions written in the project.
| File | Definition/Prototype |
|---|---|
0-sum_them_all.c |
int sum_them_all(const unsigned int n, ...); |
1-print_numbers.c |
void print_numbers(const char *separator, const unsigned int n, ...); |
2-print_strings.c |
void print_strings(const char *separator, const unsigned int n, ...); |
3-print_all.c |
void print_all(const char * const format, ...); |
-
0. Beauty is variable, ugliness is constant
- 0-sum_them_all.c: C function that returns the sum of
all its paramters.
- If the parameter
n == 0, the function returns0.
- If the parameter
- 0-sum_them_all.c: C function that returns the sum of
all its paramters.
-
1. To be is to be the value of a variable
- 1-print_numbers.c: C function that prints numbers,
followed by a new line.
- The paramter
separatoris the string to be printed between numbers. - The paramter
nis the number of integers passed to the function. - If
separatorisNULL, it is not printed.
- The paramter
- 1-print_numbers.c: C function that prints numbers,
followed by a new line.
-
2. One woman's constant is another woman's variable
- 2-print_strings.c: C function that prints strings,
followed by a new line.
- The parameter
separatoris the string to be printed between the strings. - The parameter
nis the number of strings passed to the function. - If
separatorisNULL, it is not printed. - If one of the strings is
NULL, the function prints(nil)instead.
- The parameter
- 2-print_strings.c: C function that prints strings,
followed by a new line.
-
3. To be is a to be the value of a variable
- 3-print_all.c: C function that prints anything.
- Usage:
print_all("ceis", 'H', 0, "lberton"); - The paramter
formatis a list of types of arguments passed to the function (c:char,i:int,f:float,s:char *(if the string isNULL,(nil)is printed instead)) - Any other character is ignored.
- A new line is printed at the end of the function.
- Usage:
- 3-print_all.c: C function that prints anything.