another fwrite() problem

I

ibrahimover

typedef struct{
char name[10];
int no;
}TAM;

typedef struct{
char name[10];
char ch;
}HARF;


typedef struct{
TAM *i;
CHAR *c;
}DENEME;


main(){
FILE *f1;
DENEME *d;
d=(DENEME *) malloc(sizeof(DENEME)*2);
int i;

d[0].i=(TAM *) malloc(sizeof(TAM)*2);
d[0].c=(HARF *) malloc(sizeof(HARF)*2);
d[1].i=(TAM *) malloc(sizeof(TAM)*2);
d[1].c=(HARF *) malloc(sizeof(HARF)*2);

/* Every think ok for now i can get info from user like
(d[0].i[0].name,d[0].i[0].no) */

f1=fopen("c:\\deneme.txt","w+b");

/* i just wnt to write d to File*/
for(i=0;i<2;i++){

fwrite(d,sizeof(DENEME),1,f1); //if i try like this there is an
error'cannot convert '

fwrite(&d,sizeof(DENEME),1,f1) // if i try like this this time it
writes the value of pointers




fwrite(d,sizeof(TAM)*2+sizeof(HARF)*2,1,f1)// finally i try this but
it gives error agin
}


}



im able to write like this
fwrite((d+0)->i,sizeof(TAM),2,f1);
fwrite((d+0)->c,sizeof(HARF),2,f1);
but i doesnot help for my algorithms cause i want to read d so that
with one read i can have d.i[j].name

hope im could explain my problem clearly..

sorry for my english :p
 
T

tmp123

typedef struct{
char name[10];
int no;
}TAM;

typedef struct{
char name[10];
char ch;
}HARF;


typedef struct{
TAM *i;
CHAR *c;
}DENEME;


main(){
FILE *f1;
DENEME *d;
d=(DENEME *) malloc(sizeof(DENEME)*2);
int i;

d[0].i=(TAM *) malloc(sizeof(TAM)*2);
d[0].c=(HARF *) malloc(sizeof(HARF)*2);
d[1].i=(TAM *) malloc(sizeof(TAM)*2);
d[1].c=(HARF *) malloc(sizeof(HARF)*2);

/* Every think ok for now i can get info from user like
(d[0].i[0].name,d[0].i[0].no) */

f1=fopen("c:\\deneme.txt","w+b");

/* i just wnt to write d to File*/
for(i=0;i<2;i++){

fwrite(d,sizeof(DENEME),1,f1); //if i try like this there is an
error'cannot convert '

fwrite(&d,sizeof(DENEME),1,f1) // if i try like this this time it
writes the value of pointers




fwrite(d,sizeof(TAM)*2+sizeof(HARF)*2,1,f1)// finally i try this but
it gives error agin
}


}



im able to write like this
fwrite((d+0)->i,sizeof(TAM),2,f1);
fwrite((d+0)->c,sizeof(HARF),2,f1);
but i doesnot help for my algorithms cause i want to read d so that
with one read i can have d.i[j].name




fwrite( &d.i[j].name,... ) ??
 
T

tmp123

tmp123 said:
typedef struct{
char name[10];
int no;
}TAM;

typedef struct{
char name[10];
char ch;
}HARF;


typedef struct{
TAM *i;
CHAR *c;
}DENEME;


main(){
FILE *f1;
DENEME *d;
d=(DENEME *) malloc(sizeof(DENEME)*2);
int i;

d[0].i=(TAM *) malloc(sizeof(TAM)*2);
d[0].c=(HARF *) malloc(sizeof(HARF)*2);
d[1].i=(TAM *) malloc(sizeof(TAM)*2);
d[1].c=(HARF *) malloc(sizeof(HARF)*2);

/* Every think ok for now i can get info from user like
(d[0].i[0].name,d[0].i[0].no) */

f1=fopen("c:\\deneme.txt","w+b");

/* i just wnt to write d to File*/
for(i=0;i<2;i++){

fwrite(d,sizeof(DENEME),1,f1); //if i try like this there is an
error'cannot convert '

fwrite(&d,sizeof(DENEME),1,f1) // if i try like this this time it
writes the value of pointers




fwrite(d,sizeof(TAM)*2+sizeof(HARF)*2,1,f1)// finally i try this but
it gives error agin
}


}



im able to write like this
fwrite((d+0)->i,sizeof(TAM),2,f1);
fwrite((d+0)->c,sizeof(HARF),2,f1);
but i doesnot help for my algorithms cause i want to read d so that
with one read i can have d.i[j].name




fwrite( &d.i[j].name,... ) ??



Sorry, sorry, sorry:
fwrite( d.i[j].name,... ) ??
 
J

J

typedef struct{
char name[10];
int no;
}TAM;

typedef struct{
char name[10];
char ch;
}HARF;


typedef struct{
TAM *i;
CHAR *c;
}DENEME;


main(){
FILE *f1;
DENEME *d;
d=(DENEME *) malloc(sizeof(DENEME)*2);
int i;

d[0].i=(TAM *) malloc(sizeof(TAM)*2);
d[0].c=(HARF *) malloc(sizeof(HARF)*2);
d[1].i=(TAM *) malloc(sizeof(TAM)*2);
d[1].c=(HARF *) malloc(sizeof(HARF)*2);

/* Every think ok for now i can get info from user like
(d[0].i[0].name,d[0].i[0].no) */

f1=fopen("c:\\deneme.txt","w+b");

/* i just wnt to write d to File*/
for(i=0;i<2;i++){

fwrite(d,sizeof(DENEME),1,f1); //if i try like this there is an
error'cannot convert '

fwrite(&d,sizeof(DENEME),1,f1) // if i try like this this time it
writes the value of pointers




fwrite(d,sizeof(TAM)*2+sizeof(HARF)*2,1,f1)// finally i try this but
it gives error agin
}


}



im able to write like this
fwrite((d+0)->i,sizeof(TAM),2,f1);
fwrite((d+0)->c,sizeof(HARF),2,f1);
but i doesnot help for my algorithms cause i want to read d so that
with one read i can have d.i[j].name

hope im could explain my problem clearly..

sorry for my english :p


the error results because d is not a pointer however the address of
d is a pointer.

JC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Fibonacci 0
Adding adressing of IPv6 to program 1
Python code problem 2
fwrite 10
fread/fwrite 2 18
C pipe 1
URGENT 1
A process take input from /proc/<pid>/fd/0, but won't process it 0

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top