Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Problem in writ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 6 Topic 25692 of 27343
Post > Topic >>

Problem in writing structure to Binary file in C lang

by zehra.mb@[EMAIL PROTECTED] Apr 18, 2008 at 02:35 AM

Hi,
I had written application for storing employee data in binary file and
reading those data from binary file and display it in C language.
But I face some issue with writing data to binary file.
Here is my part of my code.

struct cust_data
{
	int nCAFID;
	char *szFirstName;
};

typedef struct cust_data CUST_DATA;
CUST_DATA *pCustdata = NULL;
int AddRecord()
{
           FILE *fp;
       	   fp = fopen("Input.dat","ab+");
	          return fp;
           pCustdata = malloc(sizeof(CUST_DATA));

           pCustData->szFirstName = malloc(sizeof(pCustData-
>szFirstName));

           printf("Enter CAFID : ");
           scanf("%d",&pCustData->nCAFID);

           printf("Enter First Name : ");
           scanf("%s",pCustData->szFirstName);

           fwrite(pCustData,sizeof(CUST_DATA),1,fp);

           fclose(fp);

           free(pCustData->szFirstName);
           free(pCustData)
}

now here when i write a structure to file, it writes nCAFID and
inplace of szFirstName it writes pointer to string.
But i need to write string..
if i take szFirstName as char array then it is wroking fine.....but i
want to use heap memory instead of stack..
can anyone help me..................??
thanks in advance.............
 




 6 Posts in Topic:
Problem in writing structure to Binary file in C lang
zehra.mb@[EMAIL PROTECTED  2008-04-18 02:35:56 
Re: Problem in writing structure to Binary file in C lang
Richard Heathfield <rj  2008-04-18 10:22:52 
Re: Problem in writing structure to Binary file in C lang
jt@[EMAIL PROTECTED] (Je  2008-04-18 10:57:24 
Re: Problem in writing structure to Binary file in C lang
zehra.mb@[EMAIL PROTECTED  2008-04-20 21:26:06 
Re: Problem in writing structure to Binary file in C lang
zehra.mb@[EMAIL PROTECTED  2008-04-20 21:44:16 
Re: Problem in writing structure to Binary file in C lang
santosh <santosh.k83@[  2008-04-21 15:57:38 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Sep 6 21:31:16 CDT 2008.