I want to have a file with an undetermined number of lines. I want to read it into a struct.
What I have been doing is this:
Code: Select all
#define Max_number_of_lines 25
string Original_Message[Max_number_of_lines];
After I create that string, I read the individual lines into it using this lib function I coded:
Code: Select all
void ReadFile(string file_name, int & Read_Line_i, string & message_struct[])
{
byte File_Handle;
int File_Size;
string File_Line_Message;
bool Rdone = false;
if(OpenFileRead(file_name, File_Size, File_Handle) == NO_ERR)
{
until (Rdone == true) // read the text file till the end
{
if(ReadLnString(File_Handle, File_Line_Message) != NO_ERR) Rdone = true;
message_struct[Read_Line_i] = File_Line_Message;
Read_Line_i++;
}
}
CloseFile(File_Handle);
for (int i=Read_Line_i; i < Max_number_of_lines; i++){ //Fill the rest with nothing
message_struct[i]="";
}
}
How can I size it to the exact number of lines, efficiently? For arrays, I use "ArrayInit", and that's supposed to be good, but how do I do it for structs?
How do you recommend I read a file into a struct of strings? I want to address the lines (individual strings) with a variable like this "Original_Message[LineToRead];".