hi everyone
ive just made a little program that uses structures, and memory allocation
the program comes up with a error message saying 'segmentation fault'
i think this is because there is a bug in the memory allocation part of the program but im not sure
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "simpleio.h"
struct book
{
char *author;
char *name;
}copy1;
struct book copy2;
int main()
{
copy1.author=malloc (*copy1.author * sizeof (char));
copy1.name=malloc (*copy1.name * sizeof (char));
printf("please enter the authors name and the name of the title\n");
gets(copy1.author);
gets(copy1.name);
copy2.author = copy1.author;
copy2.name = copy1.name;
free(copy1.author);
free(copy1.name);
printf("your book %s by %s is on its way in the post\n", copy2.name, copy2.author);
return 0;
}
thanks in advance