Please help! Dynamic binary tree problem
Hi I am a new C programmer and have produced a program which reads in a file and prints it out. I now need to produce a dynamically built binary tree data structure to hold results.
The program should read the data for a competitor, place this in a new structure (using memory space acquired using malloc() or calloc()) and then insert this new structure in the appropriate place within the dynamically built binary tree of structures. I am quite baffled and not sure where to start :confused:
Any ideas would be greatly appreciated x :D
Here is the code so far:
Code:
/*
This is the header file
*/
/* Field definitions for competitor structure*/
typedef struct competitor
{
char name[80];
char address[100];
char phone[30];
int comp_number;
int river_ounces;
int sea_ounces;
int fly_ounces;
} data;
Code:
#include <stdio.h>
#include "fishing.h"
main()
{
FILE * competition;
char oneword[79], filename[20];
char *c;
/* Prompt user to enter filename */
printf("Please enter name of file \n\n");
scanf("%s", filename);
/* Open file */
competition = fopen(filename, "r");
/* If fopen() fails it returns a NULL pointer so
this must always be checked for when opening a file */
if (competition == NULL)
{
printf("Error opening file\n");
exit(1);
}
else
{
do
{
/* Reads one line from the file at a time */
c=fgets(oneword, 79, competition);
if (c != NULL)
/* Display file */
printf ("%s", oneword);
}
while (c != NULL); /* Repeat until there are no more lines to read from */
}
fclose(competition);
}
Here is the text file containing the competitor details and results:
Spring Fishing.
14th April 2005.
Margaret Mouse
Skirting Board House, Mosehole, Devon. DV1 2SS
Southern 9365
1 0 1
2 7 13
0 4 5
Bert Hill
14, Priory Lane, Birmingham, West Midlands. B19 1RU
Central 2000
0 12 9
1 11 5
1 10 4
Donald Duck
Village Pond, Duckington-by-Sea. S11 1QQ
Marine 123456
1 13 10
4 7 15
2 5 7