Commit bf8960c3 authored by Matthew Burket's avatar Matthew Burket
Browse files

Addeds docs to tokenize

parent 90c96e42
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -4,14 +4,25 @@

#include "tokenize.h"

/// Takes in the user input and tokenizes it
///
/// \param string user input
/// \param output
/// \return number of tokens
int tokenize(char *string, char **output) {
    // Make strtok thread safe
    char *strtok_save;
    // Our Delimiter is a space
    char *del = " ";
    // First call is special
    output[0] = strtok_r(string, del, &strtok_save);
    char *token = output[0];
    // Number of tokens is one
    int i = 1;
    while (token != NULL) {
        // String is NULL to keep getting tokens from the string pass in the first call of strtok_r
        token = strtok_r(NULL, del, &strtok_save);
        // Set the output
        output[i] = token;
        i++;
    }