I have a PIC24 uC application that uses sprintf in a number of locations correctly. However, one instance is pushing back, refusing to properly format an argument. I have verified that all the arguments are of type uint16_t, removed any calculation from the argument list, and then type cast the external calculations. For instance, I know that one of the arguments, 'use' value is 301, sprintf displayed it as 46 which is 301-255 which led me to suspect a data type issue. This was prior to type casting an intermediate 32 bit integer calculation to 16 bit integer, both unsigned. Now the 301 value is displayed as a negative value like -1267 even though the data types are unsigned. Any helpful suggestions?
for (q=0;q<=3;q++)
{
Lcd_Set_Cursor(0, q);
position = reviewHour + q;
use = useTrack[reviewHour + q];
sprintf(review, "hour %.2d = %.2d Gal", position, use);
Lcd_Write_String(review);
}
The above code places a data point on each of four lines of a LCD character display.