(int argc, char* argv[])
{
char Continue = 'y';
int tflg=0; int wflg=0;int hflg=0; int rflg; int Cflg=0; int Fflg=0;
int temperature = 0; int RH = 1; int windSpeed = 0;
char c;
extern char *optarg;/*extern varibales have Block scope with global life time*/
extern int optind;/*option index (optind) is automatically set by getopt function*/
while ((c = getopt_long(argc, argv, "t:s:d:cfh")) != EOF)
switch (c) {
/* process option -v */
case 't':
tflg++;
temperature = atoi(optarg);
break;
/* process wind speed flag */
case 's':
wflg++;
windSpeed = atoi(optarg);
break;
/* process -d flag */
case 'd':
rflg++;
RH = atoi(optarg);
break;
/* process -C flag */
case 'c':
Cflg++;
break;
/* process -F flag */
case 'f':
Fflg++;
break;
case 'h':
hflg++;
printf("==========================\n--Let's check the help-file--\nThe available options are:\n==========================\nc switch: Enter data in celcius scale and speed in km/h\nf switch: Enter data in fahrenheit scale and speed in miles/h\nt switch: Enter temperature in celcius for c switch and in fahrenheit\nfor f switch\ns switch: Enter speed in km/h for c switch and in miles/hr for f switch\nd switch: Enter relative humidity\nDefault values: Temperature: 0 deg, Wind-speed: 0; Relative Humidity: 1\nusage: ./as1comline [-c|-f] [-t temperature] [-s wind-speed] [-dRelative-humidity]\nEnd of Help file!\n=====================\n");
break;
}
if(hflg)
{
exit(2);
}
if((!Cflg && !Fflg) || (Cflg && Fflg))
{
printf("Choose either celsius or farenheit, celsius chosen\n");
Cflg = 1; Fflg = 0;
}
if(Cflg)
{
while(RH <= 0){printf("Enter relative humity (greater than zero): ");scanf ("%d", &RH); }
printf("\nThe following data-items have been processed for you:\n");
printf("Temperature: %d deg C\n", temperature );
printf("Wind-speed: %d km/h\n", windSpeed);
printf("Relative Humidity: %d\n ", RH);
printf("\nFinal Output: \nThe dewpoint is %.0f deg C (%.0f deg F) \n", dewpoint( temperature , RH), convert_to_fahrenheit(dewpoint( temperature, RH ) ) );
if(convert_to_celsius(temperature) < -49 || convert_to_celsius(temperature) > 4 || convert_to_Km(windSpeed) <= 5)
{
printf("!!! Windchill is only valid for windspeeds greater than 5 km/h and temperatures in the range of -49 to +4 degrees Celsius!!!\n");
}
else
{
printf("The windchill feels like %.0f deg C (%.0f deg F)\n", windchill( temperature, windSpeed), convert_to_fahrenheit( windchill(temperature , windSpeed ) ) );
}
}
if(Fflg)
{
while(RH <= 0){printf("Enter relative humity (greater than zero): ");scanf ("%d", &RH); }
printf("\nThe following data-items have been processed for you:\n");
printf("Temperature: %d deg F\n", temperature );
printf("Wind-speed: %d miles/h\n", windSpeed);
printf("Relative Humidity: %d\n ", RH);
printf("\nFinal Output: \nThe dewpoint is %.0f deg F (%.0f deg C) \n", convert_to_fahrenheit(dewpoint( convert_to_celsius( temperature ), RH) ), dewpoint( convert_to_celsius( temperature), RH ) );
if(convert_to_celsius(temperature) < -49 || convert_to_celsius(temperature) > 4 || convert_to_Km(windSpeed) <= 5)
{
printf("!!! Windchill is only valid for windspeeds greater than 5 km/h and temperatures in the range of -49 to +4 degrees Celsius!!!\n");
}
else
{
printf("The windchill feels like %.0f deg C (%.0f deg F) \n", convert_to_fahrenheit( windchill( convert_to_celsius( temperature ), convert_to_Km(windSpeed) ) ), windchill(convert_to_celsius( temperature ), convert_to_Km(windSpeed) ) );
}
}
}