Louis Pelletier
Louis Pelletier

Reputation: 31

How to Handle reading empty values at the end of a .csv file C

Somewhat of a beginner here.

Ex: 12cx7,14:53:00,0.968900025,0,0,,0,

The end has no value in this case (for this problem the value can be 1-4 but I think the way I read it should be fine)

The way I was thinking of handling it was to handle it the same way I would a double comma (an empty mid value) using strstr to find ",," and strcpy to replace it with a ",-1,". Would I be able to do that with the same setup but with ",/n" and replace with ",-1/n"

Upvotes: 0

Views: 780

Answers (1)

bruno
bruno

Reputation: 32596

you can just add an extra ',' at the end of the string to parse, so you will get the last field between the last two ','

if the last field is present you will get it, if it is absent you will get an empty string

Upvotes: 1

Related Questions