Question
In c language. I have to read 3 files and used the numbers in the file in a program. An example of the 3 files are below. How do read the numbers, I realize it’s with arrays. The input won’t have more than 100 lines but it can have less n

3. Input Files The filename includes the variable name and the sensor number as: variable name <sensor id txt For example BT 0001.txt is the file that contains the body temperature data collected for patient ID 0001 NOTE: al time stamps (days) are integers-and all data are collected within 100 day period. Some data on some days may be missing- in this case you will need Linear Interpolation BT files have the following format time stamp value> For example 0034 0054 0074 97.5 97.4 97.6 BP files have the following format: time stamp «В PD> BPS For example 0024 0044 0064 78 79 76 118 119 119 HR files have the following format: Stime stamp value> For example 0034 0035 0036 96 94 98
0 0
Add a comment Improve this question Transcribed image text
Answer #1

C CODE:

#include <stdio.h>

int main()
{
//CHANGE THE PATH OF FILES ACCORDINGLY
char *filepath1 = "M:\data1.txt"; //path for BT file
char *filepath2 = "M:\data2.txt"; //path for BP file
char *filepath3 = "M:\data3.txt"; //path for HR file

FILE *inputFile1;
FILE *inputFile2;
FILE *inputFile3;

//function to open a file and keep the contents in a file variable
inputFile1=fopen(filepath1,"r");

//Declaring array for Storing values of BT file in arrays
long timestamp_BT[100];
float value_BT[100];

//Declaring array for Storing values of BP file in arrays
long timestamp_BP[100],BPS[100],BPD[100];

//Declaring array for Storing values of HR file in arrays
long timestamp_HR[100],value_HR[100];


int t1=0,t2=0,t3=0; //will store No_of_entries in table 1 2 & 3 respectively
if(inputFile1==NULL)
{
printf("Input File 1 cannot be opened.");
return 0;
}
printf("****File1 content****\n");
while(!feof(inputFile1)) // while loop while which run until end of file is reached
{
fscanf(inputFile1,"%ld %f",&timestamp_BT[t1],&value_BT[t1]);
printf("\n%ld %.2f",timestamp_BT[t1],value_BT[t1]);
t1++;
}
printf("\n\n");
fclose(inputFile1);


inputFile2=fopen(filepath2,"r");
if(inputFile2==NULL)
{
printf("Input File 2 cannot be opened.");
return 0;
}
printf("****File2 content****\n");
while(!feof(inputFile2))
{
fscanf(inputFile2,"%ld %ld %ld",&timestamp_BP[t2],&BPD[t2],&BPS[t2]);
printf("\n%ld %ld %ld",timestamp_BP[t2],BPD[t2],BPS[t2]);
t2++;
}
printf("\n\n");
fclose(inputFile2);

inputFile3=fopen(filepath3,"r");
if(inputFile3==NULL)
{
printf("Input File 3 cannot be opened.");
return 0;
}
printf("****File3 content****\n");
while(!feof(inputFile3))
{
fscanf(inputFile3,"%ld %ld",&timestamp_HR[t3],&value_HR[t3]);
printf("\n%ld %ld",timestamp_HR[t3],value_HR[t3]);
t3++;
}
printf("\n\n");
fclose(inputFile3);

printf("No_of_entries_in_table_1=====%d\nNo_of_entries_in_table_2=====%d\nNo_of_entries_in_table_3=====%d",t1,t2,t3);
return;
}

CODE SCREENSHOTS:

Start here X Untitled1.c X #include <stdio.h> 2 int main () //CHANGE THE PATH OF FİLES ACCORDINGLY char filepath2M:data2.xt char filepath3M:data3.xt //path for BT file //path for BP file //path for HR file 10 FILE inputFilel; FILE inputFile2: FILE inputFile3: 12 13 /function to open a file and keep the contents in a file variable inputFilel-fopen (filepathl, r 15 16 /Declaring array for Storing values of BT file in arrays long timestamp BT [100] float value 18 19 20 21 //Declaring array for Storing values of BP file in arrays long timestamp BP100], BPS [100],BPD[100] 23 24 25 26 27 28 29 30 /Declaring array for Storing values of HR file in arrays long timestamp_HR[100], value_HR[100]: int t1=0,t2=0,t3=0; //will store No of entries in table 1 2 & 3 respectively if (inputFilel-NULL)

RESPECTIVE FILES SCREENSHOTS:

OUTPUT SCREENSHOT:

Add a comment
Know the answer?
Add Answer to:
In c language. I have to read 3 files and used the numbers in the file...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I am trying to read from a file with with text as follows and I am...

    I am trying to read from a file with with text as follows and I am not sure why my code is not working. DHH-2180 110.25 TOB-6851 -258.45 JNO-1438 375.95 CS 145 Computer Science II IPO-5410 834.15 PWV-5792 793.00 Here is a description of what the class must do: AccountFileIO 1. Create a class called AccountFileIO in the uwstout.cs145.labs.lab02 package. (This is a capital i then a capital o for input/output.) a. This class will read data from a file...

  • Question 2 b) Find the a-score for the babies have weight 18.5 lbs c) Find the...

    Question 2 b) Find the a-score for the babies have weight 18.5 lbs c) Find the percentage of babies have weight between 104 lbs, and I Q2) By using the Standard Normal following 18.5 tbs Distribution table (2-values table) calculate the A) PI-154sr2.03) B) P(zz3.12) 3.3 0005 0005 0005 0004 0004 0004 0004 0004 0004 0003 -3.2 0007 0007 0006 000,0006 0006 0006 000 000 000s 31 .0010 0009 0009 00090008 0008 0008 0008 0007 0007 0 0013 0013 0013...

  • I'm not getting out put what should I do I have 3 text files which is...

    I'm not getting out put what should I do I have 3 text files which is in same folder with main program. I have attached program with it too. please help me with this. ------------------------------------------------------------------------------------ This program will read a group of positive numbers from three files ( not all necessarily the same size), and then calculate the average and median values for each file. Each file should have at least 10 scores. The program will then print all the...

  • I will glady give a thumbs up to whomever can answer the question for me. Thank...

    I will glady give a thumbs up to whomever can answer the question for me. Thank you very much. Joanette, Inc., is considering the purchase of a machine that would cost $550.000 and would last for 6 years, at the end of which, the machine would have a salvage value of $55,000. The machine would reduce labor and other costs by $115,000 per year. Additional working capital of $9,000 would be needed immediately, all of which would be recovered at...

  • Windhoek Mines, Ltd., of Namibia, is contemplating the purchase of equipment to exploit a mineral deposit...

    Windhoek Mines, Ltd., of Namibia, is contemplating the purchase of equipment to exploit a mineral deposit on land to which the company has mineral rights. An engineering and cost analysis has been made, and it is expected that the following cash flows would be associated with opening and operating a mine in the area: Cost of new equipment and timbers Working capital required Annual net cash receipts Cost to construct new roads in year three Salvage value of equipment in...

  • Lou Barlow, a divisional manager for Sage Company, has an opportunity to manufacture and sell one...

    Lou Barlow, a divisional manager for Sage Company, has an opportunity to manufacture and sell one of two new products for a five- year period. His annual pay ralses are determined by his division's return on investment (RO), which has exceeded 22 % each of the last three years. He has computed the cost and revenue estimates for each product as follows: Product A Product B Initial investment: Cost of equipment (zero salvage value) Annual revenues and costs: Sales revenues...

  • Wendell’s Donut Shoppe is investigating the purchase of a new $34,600 donut-making machine. The new machine...

    Wendell’s Donut Shoppe is investigating the purchase of a new $34,600 donut-making machine. The new machine would permit the company to reduce the amount of part-time help needed, at a cost savings of $6,200 per year. In addition, the new machine would allow the company to produce one new style of donut, resulting in the sale of 2,200 dozen more donuts each year. The company realizes a contribution margin of $2.00 per dozen donuts sold. The new machine would have...

  • Oakmont Company has an opportunity to manufacture and sell a new product for a four-year period....

    Oakmont Company has an opportunity to manufacture and sell a new product for a four-year period. The company's discount rate is 18%. After careful study, Oakmont estimated the following costs and revenues for the new product: Cost of equipment needed Working capital needed Overhaul of the equipment in year two Salvage value of the equipment in four years $ 230,000 $ 84,000 $ 9,000 $ 12,000 Annual revenues and costs: Sales revenues Variable expenses Fixed out-of-pocket operating costs $ 400,000...

  • hi, can you please help me with required 1 through 6B. thanks and have a great...

    hi, can you please help me with required 1 through 6B. thanks and have a great day Lou Barlow, a divisional manager for Sage Company, has an opportunity to manufacture and sell one of two new products for a five-year period. His annual pay raises are determined by his division's return on investment (ROI), which has exceeded 20% each of the last three years. He has computed the cost and revenue estimates for each product as follows: Product $ 250,000...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT