G
G
German2018-07-04 20:37:16
C++ / C#
German, 2018-07-04 20:37:16

How to find empty (not occupied) elements in a char array?

There is a char array consisting of 16 characters, for example containing the word "Cats", the remaining 12 elements were not used, how to find the number of unused elements?
My goal is to copy such a word into another array without these elements, that is, I need to know their number.
It should be noted that the size of the word is not initially known and there can be any word, no more than an array, of course.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
C
ColdSpirit, 2018-07-04
@ColdSpirit

if (ch != 0) {...}

R
res2001, 2018-07-04
@res2001

You can copy C strings using strcpy() or similar functions - it will copy only the significant elements of the string buffer, including the terminating '\0' character.

G
GavriKos, 2018-07-04
@GavriKos

Question for question - what is the value of the unoccupied array elements?
The answer is, if you didn't initialize the array with values, it's unknown (usually).
Therefore, we fill the array with what we know. Copy cats there. We count the amount of what we know in a cycle.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question