In my my program, I am simply reading wind direction from a sensor. I am having trouble printing out the English version of the direction. The basic algorithm is this:
(values are in degrees, read from a struct)
string direction; (I know you have to create a char array, just not sure how)
if(sensor.windir > 11 && sensor.windspeed < 34)
{
direction = "NNE";
}
if(sensor.windir > 34 && sensor.windspeed < 57)
{
direction = "NE";
}
.....
printf(" Current windir is %s\n", direction);
I’m rusty on C and need a refresher on how to print the wind direction string based on its value range defined in the “if” statements. I will not need more than 3 chars in my string.
For your problem at hand, the following will do:
This only works for compile-time constant string literals.
If you need to create dynamic strings, you need to create a
chararray (likechar buf[1024];) and use something likesnprintfto populate it with a string.