Ok, I have a problem. I have to make a program in which there is a struct Student with 3 char arrays. The information is written in a textual file and I need to read from it and each Student object which has certain characteristics must be printed to the screen(I'm not telling you these characteristics cause I'm not asking for a solution of a whole problem). The char arrays have certain number of elements so I guess that eases a problem a bit. Here's what I can't understand.
How is information in a text written? For example, name char array has 20 elements and we have a name of 15 characters. How will the information in text be written? For example, "SomeRandomStdnt" has 15 characters. How will it be written in a text file, cause if I have char arrays of certain determined size - that is to help me to determine how much student records is in the text file. So Student object has 3 char arrays, all of size 20, so in a text file it will be NumberOfElements/(3*20) = number of student records.
But how are characters in a text file written? Is it like "SomeRandomStdnt_____" or something different?
I'm trying to learn about this so I can try to make a program.
Cant help you with that, but i do know that there will be an endline character at the end of the strings. So an array with 20 elements will have 19 characters + endline. It wont be printed though.
And i believe getline will skip that last character?
And there was something with spaces also, doesnt read past the first space or something.
Hmm..I just outputted a char array which is size of 20 and has characters 5 ("Arnes") and I hoped that in the text file it will be something like Arnes + some kind of empty spaces or zeros or something different.But it was just "Arnes" and nothing more. The thing is I have to extract information from the text file to a, lets say string variable. OK I can do that. Since I have the sizes of all the variables of Student struct than I know size of Student struct itself. So I just divide size of the entire string variable with size of Student struct and I learn how much student records is in it. But for me to know this, in text file, information has to be written in a strict form like "Arnes+SomeEmptySpacesOrOtherUntilSizeOfCharArray".
Its like this:
"JohnWeemanBoston" = PROBLEM since I don't know how large is the first name nor lastname nor city.
EMPTY SPACES BELLOW DO NOT WONT TO SHOW UP( I GUESSING BECAUSE REGULAR EXPRESSION OR SOMETHING)
"John Weeman Boston " = 15+15+15 = 45 characters which is, for example, the size of Struct object. So this way I would have right information. PLEASE, if anybody knows what the hell am I talking give me a solution.
Here is the whole problem I have to solve.
We have a struct: