vlakas1981
Programmer
hello everyone..
Here is my very urgent problem:
i had a previous post a little time ago, and i got an answer which i thought would help but it didn't (by xwb).
Here's the problem:
i've got a table (l_table) of i elements, every single one being a struct of the following type:
struct coded_letter{
int size;
int *elem;
};
i is 256. i use l_table.size as the counter of the elements pointed at by the pointer *elem.
(I regard *elem as a table, so i use it as l_table.elem[j]).
I do some processes, populate this table, and then i want to save it to a file.
I used this (proposed by xwb) process:
for (i = 0; i < 256; i++){
fwrite (&l_table.size,sizeof(l_table.size),1,fps);
fwrite (l_table.elem,sizeof (*l_table.elem),l_table.size, fps);
}
and then read them using
for (i = 0; i < 256; i++){
fread (&l_table.size, sizeof(l_table.size), 1, fps);
l_table.elem = malloc ((l_table.size) * sizeof (*l_table.elem));
fread (l_table.elem, sizeof (*l_table.elem), l_table.size, fps);
}
(again by xwb).
the problem is that, although everything seems to be ok when writing the data, when i read them,
i get a l_table.size of 0 for every i except for i=1, for which i get l_table.size=4456544!!!
I also get nothing in l_table.elem for any i, not even for i=1.
Thanks very much for any helpful answer.
vlakas1981
Here is my very urgent problem:
i had a previous post a little time ago, and i got an answer which i thought would help but it didn't (by xwb).
Here's the problem:
i've got a table (l_table) of i elements, every single one being a struct of the following type:
struct coded_letter{
int size;
int *elem;
};
i is 256. i use l_table.size as the counter of the elements pointed at by the pointer *elem.
(I regard *elem as a table, so i use it as l_table.elem[j]).
I do some processes, populate this table, and then i want to save it to a file.
I used this (proposed by xwb) process:
for (i = 0; i < 256; i++){
fwrite (&l_table.size,sizeof(l_table.size),1,fps);
fwrite (l_table.elem,sizeof (*l_table.elem),l_table.size, fps);
}
and then read them using
for (i = 0; i < 256; i++){
fread (&l_table.size, sizeof(l_table.size), 1, fps);
l_table.elem = malloc ((l_table.size) * sizeof (*l_table.elem));
fread (l_table.elem, sizeof (*l_table.elem), l_table.size, fps);
}
(again by xwb).
the problem is that, although everything seems to be ok when writing the data, when i read them,
i get a l_table.size of 0 for every i except for i=1, for which i get l_table.size=4456544!!!
I also get nothing in l_table.elem for any i, not even for i=1.
Thanks very much for any helpful answer.
vlakas1981