0

Suppose i want to read a line from a file, one by one. I want to split the line into tokens, which space (' ') delimiter.

First line is : Probability allows us to quantify uncertainty and randomness in a principled way.

I want to write a function (getToken) which would take a char* as input, indicating where it should start
* Then returns a char* pointing to a string which is a copy of the next token
* If the function succeeds, it returns a C string (delimited by '\0')
* containing the token. Else it returns 0.

I want to recursive call this function until line ends, how would the logic behind this go.

BLUEPIXY
  • 39,699
  • 7
  • 33
  • 70
  • 1
    Look here http://www.tutorialspoint.com/c_standard_library/c_function_strtok.htm – Ishay Peled Jul 07 '16 at 09:10
  • Hi, yes i know about this function. If i dint have to use this getToken functions, and just do it seperately all together in one function, then it would be easy. But i dont get what the function wants. Suppose for first iteration, i would pass the whole line as input, and i would get frist token. But what can i do for second iteration, 2nd token? – YoungStonerLIfe Jul 07 '16 at 09:11
  • What is your question? What is the specific problem? What have you done so far? – Lundin Jul 07 '16 at 09:12
  • @Lundin I dont get how i can get the token one by one and store it dynamically. I can use while loop and strtok() and get all tokens and store all into array. But i have to use a function which will give me one token at a time, which i will use to store in array. How will it be possible to get 10th token? – YoungStonerLIfe Jul 07 '16 at 09:16
  • There are already a lot of questions how to use `strtok`. And read the description carefully. If you still don't understand, maybe you missed the required prerequisites? – too honest for this site Jul 07 '16 at 09:19
  • http://ideone.com/egxmvY – BLUEPIXY Jul 07 '16 at 11:21

0 Answers0