Skip to main content
  1. About
  2. For Teams
Asked
Modified 13 years ago
Viewed 6k times
2

I have the following char inside an Arduino sketch:

char inData[80];

When I print to the serial console:

Serial.print(strlen(inData) - 1);

I'm expecting to see: 79 instead I see: 655356553501234567

Can someone shed some light as to why this is happening?

1 Answer 1

5

strlen is looking for a terminating nul. Calling it on an uninitialized array or pointer results in undefined behavior. You want sizeof(inData) instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.