Z
zehra.mb
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-
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.............
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.............