i need a program that will do this in C Hurricane data Downl
i need a program that will do this in C
Hurricane data Download the attached file that contains hurricane data: each line is a record containing name, year and category of a hurricane. The very first line, however, contains the number of records in the file. Read the data in the file. Use dynamic memory allocation to provide for the space of the data to be read. Then print out the oldest records of the storms in each of the categories 5, 4 and 3.Solution
code
#include <stdio.h>
#include <stdlib.h>
FILE *record;
int main()
{
int total_records=12;
char *strom_name[100];
int *year;
int *type;
int i;
record=fopen(\"record.dat\",\"r\");
if (record==NULL)
{
printf(\"file opening error\ \");
}
else
{
fscanf(record,\"%d\",&total_records);
strom_name[100]=(char *)malloc(100*total_records);
year=(int *)malloc(sizeof(int)*total_records);
type=(int *)malloc(sizeof(int)*total_records);
for (i=0;i<total_records;i++)
{
fscanf(record,\"%s%d%d\",strom_name[i],&year[i],&type[i]);
}
printf(\"records of categorie 5\ \");
for(i=0;i<total_records;i++)
{
if (type[i]==5)
{
printf(\"%s %d\ \",strom_name[i],year[i]);
}
}
printf(\"records of categorie 4\ \");
for(i=0;i<total_records;i++)
{
if (type[i]==4)
{
printf(\"%s %d\ \",strom_name[i],year[i]);
}
}
printf(\"records of categorie 3\ \");
for(i=0;i<total_records;i++)
{
if (type[i]==3)
{
printf(\"%s %d\ \",strom_name[i],year[i]);
}
}
}
return 0;
}
note:
strom record file name should be \"record.dat\".

