Simplest (but also least flexible and with some pitfalls is to use scanf):
#include <stdio.h>
struct Record {
int temperature;
unsigned int pressure_segment;
double slope;
int offset;
};
int readRecord(FILE* f, Record* rec) {
if (fscanf(f,
"Temperature = %i Pressure Segment %u Slope = %lf Offset = %i\n",
&rec->temperature,
&rec->pressure_segment,
&rec->slope,
&rec->offset) == 4) {
return 0;
} else {
return -1;
}
}
Record rec;
FILE* f = fopen("your-file-name", "r");
while (!feof(f)) {
if (readRecord(f, &rec) == 0) {
printf("record: t: %i p: %u s: %lf o: %u\n",
rec.temperature,
rec.pressure_segment,
rec.slope,
rec.offset);
}
}
fclose(f);
For any advanced use (read anything more than quick and dirty solutions) I recommend to use some of csv libraries scattered around internet.
EDIT: Version of readRecord for edited question (each record on a separate line).
int readRecord(FILE* f, Record* rec) {
if (fscanf(f,
"Temperature = %i\nPressure Segment %u\nSlope = %lf\nOffset = %i\n",
&rec->temperature,
&rec->pressure_segment,
&rec->slope,
&rec->offset) == 4) {
return 0;
} else {
return -1;
}
}