-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathargparse.c
More file actions
65 lines (60 loc) · 1.74 KB
/
argparse.c
File metadata and controls
65 lines (60 loc) · 1.74 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "argparse.h"
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
#include <errno.h>
#define FALSE (0)
#define TRUE (1)
/*
* argCount
*
* Counts the number of arguments in a given input line.
* You may assume only whitespace is used to separate arguments.
* argCount should be able to handle multiple whitespaces between arguments.
*
* Args:
* line: intput string containing command and arguments separated by whitespace
*
* Returns:
* The number of arguments in line.
* (The command itself counts as the first argument)
*
* Example:
* argCount("ls -l /home") returns 3
* argCount(" ls -l /home ") returns 3
*/
static int argCount(char*line)
{
//write your code
}
/*
* argparse
*
* Parses an input line into an array of argument strings.
* In other words, this function separates a command string into the command and its
* arguments.
*
* You may assume only whitespace is used to separate arguments.
* argparse should be able to handle multiple whitespaces between arguments.
* The function should dynamically allocate space for the array of argument strings,
* following the project requirements. The caller is responsible for freeing this memory.
*
* Args:
* line: input string containing command and arguments separated by whitespace
* argcp: stores the number of arguments in the line (argCount)
*
* Returns:
* An array of strings (one per argument). The first string is the command.
*
* Example:
* argparse("ls -l /home", &argc) --> returns ["ls", "-l", "/home"] and set argc to 3
* argparse(" ls -l /home ", &argc) --> returns ["ls", "-l", "/home"] and set argc to 3
*/
char** argparse(char* line, int* argcp)
{
//write your code
}