Answer:
#include <stdio.h>
#include <string.h>
void main( )
{
array flowerProp[2];
FILE *fp; // file pointer
char flower[255]; // creating a char array to store data
fp = fopen("flowers.dat","r");
if (fp == NULL){
printf("File flower.dat does not exist");
return;
}
// assuming the growing condition is next line to the flower name.
while(fscanf(fp, "%s", flower)!=EOF){
flowerProp.push(flower);
if (flowerProp.length == 2){
printf("%s: %s\\ ", flowerProp[0], flowerProp[1]);
memset(flowerProp, 0,0);
}
}
fclose (fp );
}
Step-by-step explanation:
The algorithm creates a pointer to the memory location to the file starting position, the character size is used to get a string from the file line by line. Then it opens and checks if the file exists.
If the file exists, the while gets the name and growth condition of the flower, saves it to an array, prints the name and condition, and clears the array for the next flower type in the loop.