Day 18


/* */
/* This program reads the information for a hurricane */
/* from a data file and then prints it, using a function. */
#include <stdio.h>
#define FILENAME "storms2.txt"
struct tsunami get_info(void);
/* Define structure to represent a hurricane. */
struct hurricane
{
char name[10];
int year, category;
};
int main(void)
{
/* Declare variables and function prototype. */
struct hurricane h1;
FILE *storms;
void print_hurricane(struct hurricane h);
/* Read and print information from the file. */
storms = fopen(FILENAME,"r");
if (storms == NULL)
printf("Error opening data file. \n");
else
{
while (fscanf(storms,"%s %d %d",h1.name,&h1.year,&h1.category) == 3)
print_hurricane(h1);
fclose (storms);
}
/* Exit program. */
return 0;
}
/* */
/* This function prints the hurricane information. */
void print_hurricane(struct hurricane h)
{
printf("Hurricane: %s \n",h.name);
printf("Year: %d, Category: %d \n",h.year,h.category);
return;
}



/* */
/* This function gets information from the user to enter */
/* into a tsunami structure. */
struct tsunami get_info(void)
{
/* Declare variables. */
struct tsunami t1;
printf("Enter information for tsunami in following order: \n");
printf("Enter month, day, year, number of deaths: \n");
scanf("%d %d %d %d",&t1.mo,&t1.da,&t1.yr,&t1.fatalities);
printf("Enter location (<20 characters, no spaces): \n");
scanf("%s",t1.location);
return(t1);
}

Comments

Popular posts from this blog

Homework 6

Another Day 23

Homework4