I’m writing a program that reads a stream of data and parses it into some values: either integers, floats, characters, or a compound value that contains a set of values (can be nested). How could I represent that in C? I was thinking of an union of int, float, char, then having an array of pointers to such unions for the compound value, but that can’t be nested.
I’m writing a program that reads a stream of data and parses it into
Share
(I’m imagining that you are parsing an Xml file)
We’ll assume that you have a bunch of nodes. Each node can have a value, it can be one of a set of sibling, and it could have children. That would give you a struct like:
DATAcould be a union like you described, or separate variables. However, since you will reading values from it in the same form as you stored them, a union should be fine.DATATYPEshould be an enum.