-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_width.c
More file actions
48 lines (44 loc) · 911 Bytes
/
Copy pathparse_width.c
File metadata and controls
48 lines (44 loc) · 911 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
40
41
42
43
44
45
46
47
48
#include "main.h"
/**
* is_digit - check if is digit
* @c: character
* Return: check
*/
int is_digit(char c)
{
return (c >= '0' && c <= '9');
}
/**
* parse_format_width - add descr
* @format: character representing specific format specifier
* @index: add descr
* @args: add descr
* Return: width
*/
int parse_format_width(const char *format, int *index, va_list args)
{
int current_index = *index + 1;
int width = 0;
while (format[current_index] != '\0')
{
if (is_digit(format[current_index]))
{
/* Accumulate the width value */
width = width * 10 + (format[current_index] - '0');
current_index++;
}
else if (format[current_index] == '*')
{
/* Handle '*' specifier for width */
current_index++;
width = va_arg(args, int);
break;
}
else
{
break; /* Invalid character, exit loop */
}
}
*index = current_index - 1; /* Update index pointer */
return (width);
}