Well, there's a whole bunch of memory allocation problems, and some other stuff to fix
> struct atom_record
> {
> int atom_number;
> char* atom_name1[3];
> char* atom_name2[3];
> char* atom_name3[3];
> char* atom_name4[3];
> char* atom_name5[4];
> int residue_number;
> char* residue_name[4];
> }a;
Ok, several things wrong here (judging from the rest of the code).
1. Each element doesn't need to be an array of pointers, just an array. You seem to be trying to copy in a string.
2. The 'a' at the end creates a variable of this type (struct atom_record), but this is a pointless variable, since you're going to be allocating them
3. name1 to name5 suggests an array
So, it should be
Code:
struct atom_record {
int atom_number;
char atom_name[5][3];
int residue_number;
char residue_name[4];
};
> struct file_record
> {
> struct atom_record **atoms;
> }*f;
Try
Code:
struct file_record {
struct atom_record **atoms;
}f;
You need a real variable at the top of the data structure to hang everything off.
> while((c=getc(f1))!=EOF)
This is fine, but you'll need to make 'c' an int, not a char, otherwise you'll never match EOF
> a=(struct atom_record *)malloc(sizeof(struct atom_record));
> f->atoms[atom_counter]=&a
This is the real problem in terms of memory allocation
I think you wanted to write it like this
Code:
f.atoms[atom_counter] = (struct atom_record *)malloc(sizeof(struct atom_record));
But this also fails, since f.atoms is itself just an uninitialised pointer.
If you know the max value of atom_count, then this fixes this problem
[code]
struct file_record {
struct atom_record *atoms[MAX_ATOM_COUNT];
}f;
Finally,
> a.residue_name[4]="GLY";
This would become
strcpy( f.atoms[atom_counter].residue_name, "GLY" );