posted Nov 14, 2018, 10:49 AM by Konstantinovich Samuel
[
updated Nov 14, 2018, 12:08 PM
]
With your table buddy, do the following in the repo "MKS65C-parseargs"
strsep is a function in string.h used to help parse stringsstrsep( <SOURCE>, <DELIMITER> ) - Locates the first occurrence of any character in the DELIMITER string and replaces it with NULL
- Returns the beginning of the original string
- sets the source string pointer to point to the index 1 byte after the location of the new NULL
- Since the source variable's value is changed, it must be a pointer to a string.
- To test it out, try the following code:
char line[100] = "woah-this-is-cool";
char *s1 = line;
printf("[%s]\n", strsep( &s1, "-" ));
printf("[%s]\n", s1);
Write a function that uses strsep to parse a line of arguments - Use the following header:
char ** parse_args( char * line ); - It should take a string with the command line invocation of a program (like
"ls -a -l" ) - Note that there is a
" " between each argument
- Return an array of pointers to each individual argument in the parameter string, that could be used for
execvp() - For example, the following code should work (assuming all variables are declared appropriately:
- You can make the following assumptions:
- There is only 1 space between each argument in the original string
- The original string contains no more than 5 arguments
- The original string is correctly formatted
|
|