Question: Please use the code provided below and make sure it is 100% correct and please don't use gets This is C program #include #include #define
Please use the code provided below and make sure it is 100% correct and please don't use gets
This is C program
#include#include #define MAX_SPECIES_NAME_LENGTH 128 #define MAX_SIGHTINGS 10000 // a struct to represent the date // a whale pod sighting was made struct date { int year; int month; int day; }; // a struct to represent a sighting // of a pod (group) of whales struct pod { struct date when; int how_many; char species[MAX_SPECIES_NAME_LENGTH]; }; int read_sightings_file(char filename[], int len, struct pod sightings[len]); int read_sighting(FILE *f, struct pod *w); int read_date(FILE *f, struct date *d); void species_count(char species[], int n_sightings, struct pod sightings[n_sightings], int *n_pods, int *n_whales); int main(int argc, char *argv[]) { if (argc != 3) { fprintf(stderr, "Usage: %s ", argv[0]); return 1; } char *filename = argv[1]; char *species = argv[2]; struct pod whale_sightings[MAX_SIGHTINGS]; int n_sightings = read_sightings_file(filename, MAX_SIGHTINGS, whale_sightings); if (n_sightings when)) != 1) { return 0; } if (fscanf(f, "%d", &(s->how_many)) != 1) { return 0; } fgetc(f); if (fgets(s->species, MAX_SPECIES_NAME_LENGTH, f) == NULL) { return 0; } // finish string at ' ' if there is one char *newline_ptr = strchr(s->species, ' '); if (newline_ptr != NULL) { *newline_ptr = '\0'; } // also finish string at ' ' if there is one - files from Windows will newline_ptr = strchr(s->species, ' '); if (newline_ptr != NULL) { *newline_ptr = '\0'; } return 1; } // return 1 if a date can be read, 0 otherwise int read_date(FILE *f, struct date *d) { int n_scanned = fscanf(f, "%d/%d/%d", &(d->year), &(d->month), &(d->day)); return n_scanned == 3; }


Download species_count.c here, or copy it to your CSE account using the following command: $ cp -n /web/dp1091/2171/activities/species_count/species_count.c. Your task is to add code to this function in species_count.c: // number of pods of the specified species assigned to *n_pods // total number of whales of the specified species assigned to *n_whales // void species_count(char species[], int n_sightings, struct pod sightings [n_sightings], int *n_pods, int *n_whales) { // REPLACE THIS COMMENT WITH YOUR CODE // THIS FUNCTION SHOULD NOT CALL SCANF OR PRINTF // IT SHOULD JUST ASSIGN VALUES to N_PODS AND N_WHALES *n_pods = 24; // CHANGE ME *n_whales = 42; // CHANGE ME } species_count.c already contains the functions which you discussed in your tutorial which reads the file of whale sightings into an arra structs. You do not need need to change these functions. The main function in species_count.c has this code: int pod_count; int whale_count; species_count(species, n_sightings, whale_sightings, &pod_count, &whale_count); printf("%d %s pods containing %d whales in %s ", pod count. species. whale count. filename) "n_poas = 24; 17 CHANGE ME *n_whales = 42; // CHANGE ME } species_count.c already contains the functions which you discussed in your tutorial which reads the file of whale sightings into an array of structs. You do not need need to change these functions. The main function in species_count.c has this code: int pod_count; int whale_count; species_count(species, n_sightings, whale_sightings, &pod_count, &whale_count); printf("%d %s pods containing %d whales in %s ", pod_count, species, whale_count, filename); Your task in this exercise is to complete species_count. Do not change any other function. species_count should assign the number of pods of the given species to *n_pods and the total number of whales of the given species to *n_whales When you have completed the function species_count this is how species_count.c should behave: $ dcc -o species_count species_count.c $ ./species_count whales.txt "Blue whale" 51 Blue whale pods containing 1171 whales in whales.txt $ ./species_count whales.txt "Indo-Pacific humpbacked dolphin" 43 Indo-Pacific humpbacked dolphin pods containing 897 whales in whales.txt
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
