-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisValidSpecifier.c
52 lines (49 loc) · 1.31 KB
/
isValidSpecifier.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdbool.h>
#include <stdio.h>
#include "main.h"
/**
* isValidSpecifier - Checks if a specifier character is valid.
*
* @specifier: The specifier character to be validated.
*
* Description:
* This function checks if the given specifier character
* is valid. It compares
* the character against a list of valid specifiers and
* returns true if a match
* is found, indicating that the specifier is valid.
*
* Return: true if the specifier is valid, false otherwise.
*/
bool isValidSpecifier(const char specifier)
{
int loopIndex;
type_list specifiers[] = {
{'c', "char"},
{'i', "int"},
{'f', "float"},
{'s', "string"},
{'d', "integer "},
{'b', "binary"},
{'u', "unsigned"},
{'o', "octal"},
{'x', "hex"},
{'X', "hex"},
{'S', "hex"},
{'p', "pointer"},
{'+', "flag"},
{' ', "flag"},
{'#', "flag"},
{'r', "char *"},
{'R', "char *"},
{0, NULL} /* Use 0 to indicate the end of the list */
};
for (loopIndex = 0; specifiers[loopIndex].theSpicifier != 0; loopIndex++)
{
if (specifier == specifiers[loopIndex].theSpicifier)
{
return (true); /* Specifier is valid */
}
}
return (false); /* Specifier is not valid */
}