Learn to Code
John F. Dumas
contact me | resume | how it works | example programs | testimonials | main page

C - Tokenizer


► Problem Description: There is a function in the c standard library strtok that has some design issues. Firstly, it modifies its first argument (the string to be tokenized) and secondly, it maintains its own internal static buffer which makes strtok non-reentrant. Create a new function called 'tokenize' that addresses both of strtok's shortcomings.


► Example Output:

exampleOne: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
[2]
[3]
[5]
[7]
[11]
[13]
[17]
[19]
[23]
[29]

exampleTwo: [127.0.0.1 4.3.2.1 100.200.300.400]
[127.0.0.1]
 [127]
 [0]
 [0]
 [1]
[4.3.2.1]
 [4]
 [3]
 [2]
 [1]
[100.200.300.400]
 [100]
 [200]
 [300]
 [400]

exampleThree: [a, b, 'c, d, e', f, 'g, h, i, j, k']
[a, b, ]
 [a]
 [b]
[c, d, e]
 [c]
 [d]
 [e]
[, f, ]
 [f]
[g, h, i, j, k]
 [g]
 [h]
 [i]
 [j]
 [k]


Source code


Back to Example Program Index


© John F. Dumas | johnfdumas@gmail.com | main page | top of page