Answer the question
In order to leave comments, you need to log in
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
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.
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 questionAsk a Question
731 491 924 answers to any question