Hi I am new to C programming and I have to produce a C program which holds data for competitors in a competition. The structure must have 5 fields, one to hold the competitor's name, one to hold a competitor number (which you allocate automatically as you read in the data for each competitor, use 1 for the first competitor, 2 for the second and so on), one to hold the river fish weight converted to ounces, one to hold the sea fish weight converted to ounces and a final field to hold the weight of fish caught in the fly fishing competition also converted to ounces.
I must also define an array with 8 elements, each of which is a structure as defined above.
The input should be exactly like this:
Competitor's name: Fred_Bloggs
Weight of Fish from the River Competition (Stones Pounds Ounces): 1 2 9
Weight of Fish from the Sea Competition (Stones Pounds Ounces): 4 10 7
Weight of Fish from the Fly Competition (Stones Pounds Ounces): 0 8 5
and the output should be outputted into a table.
Here is my code so far:
Code:
#include <stdio.h>
#include <stdlib.h>
/* Field Definitions */
typedef struct competitor {
char name;
int comp_number;
int river_fish;
int sea_fish;
int fly_fish;
} data ;
main(){
int n, count, x = 0; data *record;
printf("Please enter number of competitors:\n");
scanf("%d", &n);
/* Creates dynamic array*/
record = (data *)malloc(n * sizeof(data));
for(count = 0; count <= (n-1); count++){
printf("Please enter name competitor # %d\n", count+1);
scanf("%s", &record[count].name);
printf("Please enter weight of Fish from the River Competition (Stones Pounds Ounces) for competitor # %d\n", count+1);
scanf("%d", &record[count].river_fish);
printf("Please enter weight of Fish from the Sea Competition (Stones Pounds Ounces) for competitor # %d\n", count+1);
scanf("%d", &record[count].sea_fish);
printf("Please enter weight of Fish from the Fly Competition (Stones Pounds Ounces) for competitor # %d\n", count+1);
scanf("%d", &record[count].fly_fish);
}
for(count = 0; count <= (n-1); count++){
{ int i,j ;
const i_limit = 8, j_limit = 5;
do {
printf("row %d:", i);
do {
printf(" %3d", j);
j = j+1;
} while (j < j_limit);
printf("\n");
i++;
} while ( i <=i_limit) ;
}
printf("Name: %s\n", (&record[count].name));
printf("River Fishing: %d\n", (&record[count].river_fish));
printf("Sea Fishing: %d\n", (&record[count].sea_fish));
printf("Fly Fishing: %d\n", (&record[count].fly_fish));
}
}
Please help, I would be eternally grateful! x