Skip to content

Implement the command tokenizer #9

@nanafox

Description

@nanafox

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

Metadata

Metadata

Labels

featureimplemented a featuretasknew task accomplised

Type

No type

Projects

Status

📋 Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions