Input Checker Function
A function to check and validate different 5 types of input
Last updated
A function to check and validate different 5 types of input
Last updated
About: the check() function performs different types of validation checks based on the value of the enum type
parameter.
This line includes a header file named "includes.h"
(see in #1.-included-header-file).
This header file likely contains the necessary include statements for required libraries and dependencies. By including this file, all the necessary libraries are made available for the code to work properly.
Here we need it to import the stdarg.h
, string.h
and ctype.h
library (explained in )
This line declares an enumeration type named type
that represents different validation checks. The possible values of this enumeration are isAlpha
, isEmail
, coef
, avg
, and age
.
Since it's a function which checks 5 types of inputs, we made a switch case to handle each type of inputs, dependes on enum type Something
argument passed value
This code block validates if the given string str
consists only of alphabetic characters. It iterates over each character in the string and checks if it is an alphabet character using the isalpha
function from(ctype.h).
If any non-alphabetic character is found, the function returns false
. Otherwise, if all characters are alphabetic, it returns true
.
This code block validates if the given string str
represents a valid email address. It checks if the string contains the '@' symbol followed by a dot ('.') character.
It uses the strchr
function (from string.h
) to find the positions of the '@' and '.' characters in the string.
If the '@' character is not found, the function returns false
. Otherwise, it checks
This code block validates if the given integer value num
represents a valid coefficient. It checks if the coefficient is greater than zero.
If the coefficient is greater than zero, the function returns true
. Otherwise, it returns false
.
This code block validates if the given floating-point value moy
represents a valid average. It checks if the average is between 0.0 and 20.0 (inclusive).
If the average is within the valid range, the function returns true
. Otherwise, it returns false
.
This code block validates if the given integer value num
represents a valid age. It checks if the age is between 0 and 149 (inclusive).
If the age is within the valid range, the function returns true
. Otherwise, it returns false
.
Variable | Description |
---|---|
va_list args;
This variable is used to handle the variable arguments passed to the function.
char* str
It is a pointer to a character string used to store a string argument for validation.
int num
It is an integer variable used to store an integer argument for validation.
double moy
It is a double variable used to store a floating-point argument for validation.
char* at
and char* dot
These variables are pointers to characters and are used for email validation.