-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1_parse.c
32 lines (28 loc) · 819 Bytes
/
1_parse.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
#include "main.h"
/**
* parse_arguments - Parses command line arguments
* @input: The input string containing the command and arguments
* @args: Array to store the parsed arguments
*
* Return: The number of arguments parsed
*
* Description: This function tokenizes the input string using space
* as the delimiter and stores the tokens into the args array.
* It returns the total number of arguments parsed.
*/
int parse_arguments(char *input, char **args)
{
int count = 0;
char *token = strtok(input, " ");
/* Tokenize the input string */
while (token != NULL)
{
/* Copy the token into the args array */
args[count] = our_strdup(token);
count++;
token = strtok(NULL, " ");
}
/* Set the last element of args array to NULL */
args[count] = NULL;
return (count);
}