2022-09-06 12:02 PM
2022-09-06 02:40 PM
Not only terminating null character, but it can write anything past the end. It's strongly recommended to not use it at all. Instead snprintf() must be used.
2022-09-06 03:16 PM
No,
But sprintf() does return the length of the string added, but whatever buffering you have needs to be able to accommodate the C string properly.
The length would allow you to advance the pointer to the NUL, or memcpy() to a spot you can't tolerate the NUL
2022-09-07 07:40 AM
2022-09-07 08:47 AM
Why can't you make these strings wide enough to carry the data?
You don't show the prototype for OLED_countDraw, if it takes a char, pass a char
char char String[4];
sprintf (String,"%1d",Gain);
OLED_countDraw (1,1,66,String[0]); // First character
OLED_countDraw (1,1,66,String[1]); // Second character
If it expects the string, ie char *
OLED_countDraw (1,1,66,String); // Pass as string
2022-09-07 08:58 AM
If Gain is always a value between 0 and 9, wouldn't something more simple like this work?
char g = '0' + (char)Gain;
char g = (char)(0x30 + Gain);
2022-09-07 09:39 AM
2022-09-07 10:42 AM
There is no need for those casts. In the first line the addition will anyway be done on "int" type because of how integer promotion is specified. In the second line the cast is totally useless, because assignment does implicit casting anyway.
2022-09-07 10:45 AM
Do you constantly need to be such an *** ?
2022-09-07 12:07 PM
Tesla, I do not understand your reaction. I said "WOW" because i liked your response and followed that with a "Thanks". I apologize to you if if you think I responded to your answer in a negative way. I meant my response to be a "Thank You".