I am a VB programmer, so I know a lot about programming. I am just new to C and want to ask a simple question.
How can I read a file and use strtok with space as the delimiter and have access to all tokens in memory? The example provided at cplusplus.com is not exactly what I need. The thread, http://www.daniweb.com/forums/thread55584.html, on this site is also not exactly it.
The problem in the examples provided is that the char array is overwritten each time a new token is read. I need to be able to access all of the tokens from memory.
In VB I would code something like this:
Dim strline As String Dim strall As String Dim arrtok() As String Open "B:\test.txt" For Input As #1 Line Input #1, strall Do While Not EOF(1) Line Input #1, strline strall = strall & " " & strline Loop Close #1 arrtok() = Split(strall, " ") MsgBox arrtok(0), vbInformation, "This is token 1" MsgBox arrtok(1), vbInformation, "This is token 2" MsgBox arrtok(2), vbInformation, "This is token 3"
How can I do the same in C? I'd like to use char arrays for this, not c strings if possible.