@ScruffR strcpy or strcmp?
Of course Sorry for that
strcmp()
was what I meant to write
(corrected above)
While at it, I’d actually write it shorthand like this
if (!strcmp(CDATA, "NORMAL"))
I recently learned about LED Signaling in an application where in I wanted to provide a visual indication on the device of the status of the enclosed controller. In the past, I had added a RGB LED for this purpose, but realized I could simplify my circuitry and use the on-board tri-color LED to satisfy this need. I drill a small hole “above” the on-board LED and insert a piece of clear acrylic round bar. I rest it just a couple millimeters above the LED and cut it off so it’s just outside the case. It acts just like a light pipe and makes a very effective visual indicator.
good idea.
Hi @ScruffR
I use this code but when I check the output it shown unclear character . do you know why?
This suggests that your destination variable is too short to hold the entire string.
When you read the description of strncpy()
you will find that in such a case the string will not be terminated correctly and your code needs to take care of that.
Either provide a destination buffer that will definetly hold the longest expected string plus at least one byte or when you need to deal with unpredictable source data catch the return value of snprintf()
and check that against the len
parameter. When that value equals the len
you know that the source was too long and you need to put a '\0'
at the end of your buffer.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.