Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How do I read several values from one text file in C? The filename includes the

ID: 3687932 • Letter: H

Question

How do I read several values from one text file in C?

The filename includes the variable name and the sensor number as: <variable_name>_<sensor_id>.txt

For example “BT_1.txt” is the file that contains the data collected by body temperature sensor 1.

BT files have the following format:

<time_stamp> <value> <units>

<time_stamp> <value> <units>

<time_stamp> <value> <units>

The text file looks like this:

0004   97.1   mW
0014   97.4   mW
0024   97.5   mW
0034   97.2   mW

How do I get the program to read the text file, and assign the proper values to the right varibles?

Later in the program I will need to manipulate these values.

Explanation / Answer

If that is accurate your format string has to match exactly:

This assums each string field is a single block of ASCII values, no spaces/tabs etc. Your code is missing how the variables are defined, presumably it's something like:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote