I am trying to fill the storage for jones allocated by malloc with "#" using memset.
I am not having much luck......please help I think there is also something wrong with my code.
Here it is:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
FILE *fptor;
FILE *ifp;
struct phoneTemplate
{
char lastName[16];
char firstName[16];
char phoneNumber[16];
};
typedef struct phoneTemplate phoneRec;
void printRec(struct phoneTemplate *thisName);
int main(void)
{
struct phoneTemplate *smith;
phoneRec *jones;
fptor=fopen("c:\\c\\strprobfile.txt","w");
ifp=fopen("c:\\c\\strprobfile.txt","r");
smith=(struct phoneTemplate *)malloc(sizeof(struct phoneTemplate));
if (smith==NULL)
{perror("strprob3"); exit(1);}
jones=(phoneRec *)malloc(sizeof(phoneRec));
if (jones==NULL)
{perror("strprob3"); free(smith); exit(1);}
memset(jones,"#",sizeof(jones));
strcpy(smith->lastName, "Smith");
strcpy(smith->firstName, "Fred");
strcpy(smith->phoneNumber,"(212)262-7321");
strcpy((*jones).lastName, "Lowel");
strcpy((*jones).firstName, "Jones");
strcpy((*jones).phoneNumber,"(617)362-8328");
fwrite(smith,sizeof(struct phoneTemplate),1,fptor);
fwrite(jones,sizeof(struct phoneTemplate),1,fptor);
fread(smith,sizeof(struct phoneTemplate),1,ifp);
fread(jones,sizeof(struct phoneTemplate),1,ifp);
printRec(smith);
printRec(jones);
free(smith);
free(jones);
fclose(fptor);
fclose(ifp);
return 0;
}
void printRec(struct phoneTemplate *thisName)
{
printf("Name: %s, %s\n", thisName->lastName,thisName->firstName);
printf("Phone: %s\n\n", thisName->phoneNumber);
return;
}