Processing a CSV file

Hi

I'm reading a comma separated file record by record. After reading a record, I'm tokenizing it using strtok() function and moving the tokens into a structure.

But suppose if a record is of the following format,i.e two commas appear one after another, then the strtok function skips the blank token and moves to next token. But I want to Move a blank space into the corresponding structure member. How can i solve this pbm ? Can anyone help me with this please ?

123,0,2,,123

Thanks,
Jane A

I have encountered this kind of problem !

I dont think we could use strtok to have solution as u desire ( I dont know )

Quite an easy way to tackle is,
parse the record using the delimiter.

for ,

123, 1, ,, 45

parse the record till the end of the line delimiter
when delimiter ' , ' is encountered you have a token
when a delimiter ' , ' follows another delimiter ' , ' obviously the string would have nothing hence the purpose would be solved

Hope this helps !
:slight_smile: