-
Well it would work fine if the input was 0 and 1 only. I guarantee that, but it looks like the input is not so, and scanf just puts the value 0 for it is not reading anything appropriate.
If you post the content of the input, and i suspect that you should type:
> cat /home/phil4985/cs1313student/soonerglitch_telem.dat
to get that printed, we could guide you to read it appropriately.
-
Your input file is much more complicated than what you describe. With the initial values in it, your program works correctly, and prints the right thing.
It appears to me that either your assignment has a much different specification, or you are reading in a wrong file, with the first being more probable in my view.
-
There are with a quick view, 20 blocks of: 2 series of 5 pairs of 1 or 0, followed by two series of 3 pairs of 1 or 0 followed by 2 series of 5 values followed by 2 series of 3 values negative or positive, with the values delimited by a '.', and i really can understand a connection between the data but not enough to be useful.
-
yes you are correct. the assignment is to read enable and on values for a set of 5 heaters, another set of 5 heaters, then a set of 3 heaters and another set of 3 heaters. Then temperature readings for those heaters are to be read. This is done until the data input stops (so everything needs to be in a while loop).
Code:
#include <stdio.h>
#include <unistd.h>
#include <time.h>
enum on_enable {ENABLE=0, ON=1};
enum time_constants {ZERO=0, FOUR_SECONDS=4};
enum number_contants {HEATERS=5, STATES=2, BATT=3, IMU=3};
main()
{
int lower_state[HEATERS][STATES];
int upper_state[HEATERS][STATES];
int batt_state[BATT][STATES];
int imu_state[IMU][STATES];
int n;
int m;
int i;
int j;
int last_read;
double lower_temp[HEATERS];
double upper_temp[HEATERS];
double batt[BATT];
double imu[IMU];
char on_state_labels[2][4]={{"ON "},
{"OFF"}};
char enable_state_labels[2][9]={{"ENABLED "},
{"DISABLED"}};
time_t mytime;
while(1==1)
{
for (n=0; n<5; n++)
{
scanf("%d %d", &lower_state[n][ENABLE], &lower_state[n][ON]);
printf(" LOWER_%d %s "
,n,on_state_labels[lower_state[n][ON]]);
printf("%s\n", enable_state_labels[lower_state[n][ENABLE]]);
}
printf("\x1b[5A");
for (n=0; n<5; n++)
{
scanf("%d %d", &upper_state[n][ENABLE], &upper_state[n][ON]);
printf("UPPER_%d %s ",n,on_state_labels[upper_state[n][ON]]);
printf("%s\n", enable_state_labels[upper_state[n][ENABLE]]);
}
printf("\n");
for (m=0; m<3; m++)
{
scanf("%d %d", &batt_state[m][ENABLE], &batt_state[m][ON]);
printf(" BATT_%d %s "
,m,on_state_labels[batt_state[m][ON]]);
printf("%s\n", enable_state_labels[batt_state[m][ENABLE]]);
}
printf("\x1b[3A");
for (m=0; m<3; m++)
{
scanf("%d %d", &imu_state[m][ENABLE], &imu_state[m][ON]);
printf("IMU_%d %s ",m,on_state_labels[imu_state[m][ON]]);
printf("%s\n", enable_state_labels[imu_state[m][ON]]);
}
for (n=0; n<5; n++)
{
scanf("%lf", &lower_temp[HEATERS]);
printf("%s", lower_temp[HEATERS]);
}
mytime = time(ZERO);
printf("%s",ctime(&mytime));
mytime = time(ZERO);
printf("%s",ctime(&mytime));
printf("\x1b[0A");
sleep(FOUR_SECONDS);
}
}
This is the entire code that I have so far. It's obviously still a huge work in progress, but if you feel up to it you can see if I'm on the right track. I have to go to work now unfortunately, but thank you guys for all your help so far, it's much appreciated. This is so frustrating!
-
Code:
for (n=0; n<5; n++)
{
scanf("%lf", &lower_temp[HEATERS]);
printf("%s", lower_temp[HEATERS]);
}
HEATERS = 5, and you go out of bounds, try n instead.
You want to print a double, use %f
Same as the before.
Ok apart from some typical mistakes your program works fine once you complete reading the rest of the floating point data, it runs.
Hints to go on.
correct main to return int.
Drop the infinite loop and instead do a test for the end of data. (hint: don't use feof, read the forum FAQ for the correct way to test for eof)
And finally fix your indentation a bit, so that the blocks of code are clear.
Good luck.