Mail Archives: djgpp/2000/06/22/21:53:22
Hi, can someone help me with this, can you please point out what my
mistakes are.
Im trying to write this structure to a file, and then retrive it from
another program,
but i'm having troubles.
struct db{
char *url;
char test;
};
this is the code I use to write data to the file :
struct db line;
if (!(data=fopen("data.dat","wb")))
{
printf("Error opening file");
}
/* strcpy(line.url,"http://www.ironmaiden.com");*/
line.url="http://www.ironmaiden.com";
line.test='T';
fwrite(&line,sizeof(line),1, data);
fclose(data);
return (0);
and this is the code of the program I use to read the file
struct db lineread;
if (!(data=fopen("data.dat","rb")))
{
printf("Error opening file");
}
fseek(data, SEEK_SET, 0);
fread(&lineread,sizeof(lineread),1, data);
fclose(data);
return (0);
Please help me to find out what am I doing wrong.
Thanks
- Raw text -