I'm trying to read an array of character strings (theList) to a text file and then read it back into another array of character strings (inList). I need inList to be NULL terminated (as is theList) i.e I want NULL as the final entry in inList.
I'm creating the file OK but I get no output from the read back. I'm new to streams so I'm probably doing something stupid. Any ideas on making this work?
You aren't really using a list or strings. So the read section isn't doing what you think.
The 'strings' in theList aren't strings at all, they're char arrays and they all can have different lenghths.
theList is an array of these variable length char arrays that are fixed in memory somewhere.
The list you have is good enough for writing to the file, but not good enough to read from the file. You need to use strings, and as you're reading an unspecified number of items from the file, a vector.
So your declaration of data structure looks like: std::vector<std::string> anotherlist
kbw: I was a loose in my terminology - I should have said an 'array of pointers to char' rather than an 'array of character strings'.
However, I am using a pre-standard compiler (Turbo C++ - I know it's old but I'm using it!) so vectors are not available neither are 'strings'.
Is there a way to populate char *inList[numStrings]; with items read in from the file?
What I'm trying to do is: (a) hold a list of text items in a file and load it into my 'inList' at program startup. 'inList' may be subject to change during program running;
(b) at program end, save the - possibly revised - inList back out to a file.
I'm doing this so that I don't have to recompile the program every time I want to change the contents of 'inList'.