1. Engineering
2. Computer Science
3. hey i want a little help here i have got...

Question: hey i want a little help here i have got...

Question details

Hey, I want a little help here. I have got a project in C where I have to tell the weather conditions from a file and read it. There is a method that's shown below, which I need to write. I need to read the precipitation from the file of the given month and display it. How do I do it. Please tell me.

We have to solve it using fscanf, open, and fprintf and noting else.

Method:-

int precipitationPerMonth(char *file_name, int mon){
}


Example:

location
date,month,high,low,total_precipitation,rain%,snow%


Indianapolis
21_jun_2018,10,53,30,0.00,100.00%,0.00%
jan_9_2018,1,75,28,0.02,100.00%,0.00%
jul_6_2018,7,87,69,0.00,100.00%,0.00%


Now if I choose January which moth - 1, the precipitin reading should be 0.02.

Note : There is a small correction in question. The method doesn't return integer type, but it returns float type value.(according to the example given in the question)

Explanation:

A File Pointer is taken and the file is opened using fopen() function in Read Mode. FILE_PATH is the value which should be given by the user, according to the directory in which the required file exists. Then, check whether the file exists or not. If doesn't exists, then show an error message, else Read the file. The file is read through fgetc() function (fgetc - File Get Character) character by character. Initially, we looked for next line (\n) character. That is used to eliminate the line which contains name of the location. Then, we looked for comma(,) character, to identify different fields of data. Then the identified data is converted from char to integer/float depending upon the required data type. Then the required precipitation value is returned.

I Hope you'll help and I'll rate good.