Is there function that returns index of first null character in a string ?

char desc[20];

some code has added characters to desc character array.

Is there function that returns index of first null in the string.

For example,
desc[0] = 'N'
desc[1] = 'O'
desc[2] = 'T'
desc[3] = '  '
desc[4] = 'S'
desc[5] = 'E'
desc[6] = 'T'
desc[7] = 'NUL'
desc[8] = 'NUL'
desc[9] = 'NUL'
desc[10] = 'NUL'

I'm looking for a function that I can call that returns index of first 'NUL' in the string.
LVL 1
naseeamAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
Sure, it's simply 'strlen()', e.g.

int index = strlen(desc);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rshqCommented:
0
jkrCommented:
Um, I somehow guess that this is overkill to find the first NULL byte ;o)
0
phoffricCommented:
If you wanted to get a pointer to the NUL, you can use strchr:
     http://www.cplusplus.com/reference/cstring/strchr/
  char desc[] = "Not Set\0\0\0";
  int index = strlen(desc);
  char * ptrNul = strchr( desc, 0 );

  std::cout << "index = " << index
     << "  and ptrNul - desc = " << ptrNul-desc << std::endl;

  std::cout << " *ptrNul = " << static_cast<int>(*ptrNul) << std::endl;
  --ptrNul;
  std::cout << " *ptrNul = " << *ptrNul << std::endl;

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.