-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_fields.c
More file actions
40 lines (37 loc) · 908 Bytes
/
Copy pathstring_fields.c
File metadata and controls
40 lines (37 loc) · 908 Bytes
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
#include "main.h"
/**
* get_precision - Extracts the precision value from
* the provided format string.
* @p: Pointer to the current position in the format string.
* @params: Pointer to the parameter structure which
* will store the parsed precision value.
* @ap: Argument list pointer, used if precision is provided
* as an argument (e.g., ".*").
*
* Description:
* This function parses the precision
* part of a format string (like ".2" in "%.2f").
* If precision is specified using an asterisk (e.g., ".*"),
* the next argument in the va_list is used.
*
* Return: Updated pointer position after parsing the precision.
*/
char *get_precision(char *p, params_t *params, va_list ap)
{
int d = 0;
if (*p != '.')
return (p);
p++;
if (*p == '*')
{
d = va_arg(ap, int);
p++;
}
else
{
while (_isdigit(*p))
d = d * 10 + (*p++ - '0');
}
params->precision = d;
return (p);
}