-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
Description
For this task, your job will be to break a string into the required substrings based on a given delimiter. This function must return a string array. The function to use is
#include "liteshell.h"
char **tokenize(const char *str, const char *delim);This function will utilize the strtok function. Ensure you are handling memory correctly and checking for edge cases. This function will be what everyone will use for anything that requires tokenization for the entire shell. For this reason, ensure you are thinking outside of the box and bringing out something very efficient and long-lasting.
When delimiter is NULL, assume spaces and tabs. Also, terminate the array before returning it.
Example usage:
int i;
char *cmd = "Hello world";
/* call the function to tokenize on spaces */
char **cmd_array = tokenized(cmd, NULL);
/* print the array */
for (i = 0; cmd_array[i] != NULL; i++)
printf("%s\n");Expected output:
Hello
World
File: lsh_utils.c
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
📋 Backlog