S
swetha
HI Every1,
I have a problem in reading a binary file.
Actually i want a C program which reads in the data from a file which
is in binary format and i want to update values in it.
The file consists of structures of type----
struct record {
int acountnum;
char name[20];
float value;
char phone[10];
}
I wrote a program which reads in these values into a structure which i
created in my program.While printing the values i got the "name" and
"phone" values correctly ( as they are in char) ....but iam not
getting the accountnum and value fields.Iam getting some arbitary
values.SO can any1 help me out in this of how to retrieve the values
correctly ......
My code is...
struct record{
int acctnum;
char name[20];
float value;
char phone[10];
int age;
};
struct record data;
FILE *file = fopen("db07", "rb");
while ( fread(&data, sizeof (struct record), 1, file) == 1 )
{
printf("Name:%s\nAccount Number :%d\nAge:%d\nPhone:%s\nValue:%f\n",
data.name, data.acctnum,data.age,data.phone,data.value);
}
I have a problem in reading a binary file.
Actually i want a C program which reads in the data from a file which
is in binary format and i want to update values in it.
The file consists of structures of type----
struct record {
int acountnum;
char name[20];
float value;
char phone[10];
}
I wrote a program which reads in these values into a structure which i
created in my program.While printing the values i got the "name" and
"phone" values correctly ( as they are in char) ....but iam not
getting the accountnum and value fields.Iam getting some arbitary
values.SO can any1 help me out in this of how to retrieve the values
correctly ......
My code is...
struct record{
int acctnum;
char name[20];
float value;
char phone[10];
int age;
};
struct record data;
FILE *file = fopen("db07", "rb");
while ( fread(&data, sizeof (struct record), 1, file) == 1 )
{
printf("Name:%s\nAccount Number :%d\nAge:%d\nPhone:%s\nValue:%f\n",
data.name, data.acctnum,data.age,data.phone,data.value);
}