Hi,
I am new in nested structures. So I would like to get some help. In the following example I can write the "sweet" to the file. But I am unable to write the value "8" in the file through the structure variable. How should I write to put the value 8 in integer "tt" of structure "str3" and correctly able to write it in the file.
Also another question. Let say I get a data base full with the data of the following type, now I read len_ppp of the first data from the file and this value means the remaining part of the first data has this length (otherwise I cannot calculate the length of the string of the first data and the value of the integer tt pointed by *cl and tt respectively). Now getting the length of the remaining part of the data by len_ppp, how could I fetch the data from the file and print it in terminal (each data at a time)?
Code:
#include <stdio.h>
int main(){
typedef struct three{
int tt;
}str3;
typedef struct two{
str3 rt;
char *cl;
}str2;
typedef struct one{
int len_ppp;
str2 *ppp;
}str1;
str1 *pop;
pop=(str1*)malloc(sizeof(str1));
pop->len_ppp=5;
pop->ppp=(str2*)malloc(sizeof(str2));
pop->ppp->cl=malloc(5 * sizeof (char));
pop->ppp->cl="sweet";
pop->ppp->rt.tt=8;
FILE *lt;
lt=fopen("test.bin","wb");
fwrite((pop->ppp->cl), 5, 1, lt);
fwrite(&(pop->ppp->rt.tt), sizeof(int), 1, lt);
return 0;
}
Please help me to understand it and get knowledge. Thank you.
Best regards,
Wahid