i have the following struct
struct
{
char order;
int row;
int column;
int length;
char printChar;
}record;
and my file look’s like this
F
30
40
7
X
how can i use fread to store the file in the struct?
does my file appear correctly or should all the components need to be in one-line?
If I understand correctly, you’re asking if you can do
or are you forced to use
If this is your question, then the answer is: you have to read the fields one-by-one since there may be padding between struct members. Or, if you use a GNU-compatible compiler, you might instruct it not to include any padding by declaring your struct as “packed”:
But this is not advised unless absolutely necessary (it’s not portable).
Also, is your file really a binary file? If not, you should pay attention to newline characters and converting the numbers from text to their actual numeric value.