pepsi_max2k
03-15-2005, 10:19 PM
Hi guys, i'm a n00b c programmer trying to produce somthing for a uni assignment, just wondered if you could look over the following and let me know if it's ok...
/* Allocate memory to create entry. */
current_entry = (struct entry *) malloc(sizeof(struct entry));
current_entry_ptr = current_entry;
/*
* Get competitor details until end of the file is reached.
* Add each set of details to an entry strut.
*/
while(!feof(input_file)) {
fgets(current_name, MAX_INPUT_LINE_SIZE, input_file);
strcpy(current_entry_ptr -> name, current_name);
/* Unless end of file has been reached, add struc to array. */
if (!feof(input_file)) {
current_entry_ptr++;
}
}
basically its part of my program where i'm trying to create numerous entries (structures) using alocated memory. eventually they'll form part of a binary tree but i wanna make sure this lot's ok first. it's all working and everything, but i just wondered if the memorie's actually being allocated correctly, cos from what i can see it allocates enough for one entry, adds details to it via the current_entry_ptr, then increments current_entry_ptr to create a new entry, but i'm not sure if that means it gets allocated more memory or not. i'm kinda confused by it all. still, java's worse :p and i'm still not sure how to store a tree :rolleyes:
/* Allocate memory to create entry. */
current_entry = (struct entry *) malloc(sizeof(struct entry));
current_entry_ptr = current_entry;
/*
* Get competitor details until end of the file is reached.
* Add each set of details to an entry strut.
*/
while(!feof(input_file)) {
fgets(current_name, MAX_INPUT_LINE_SIZE, input_file);
strcpy(current_entry_ptr -> name, current_name);
/* Unless end of file has been reached, add struc to array. */
if (!feof(input_file)) {
current_entry_ptr++;
}
}
basically its part of my program where i'm trying to create numerous entries (structures) using alocated memory. eventually they'll form part of a binary tree but i wanna make sure this lot's ok first. it's all working and everything, but i just wondered if the memorie's actually being allocated correctly, cos from what i can see it allocates enough for one entry, adds details to it via the current_entry_ptr, then increments current_entry_ptr to create a new entry, but i'm not sure if that means it gets allocated more memory or not. i'm kinda confused by it all. still, java's worse :p and i'm still not sure how to store a tree :rolleyes: