How do i count all the characters in a string?
How do i count all the characters in a string?
With size() method. Or if you are using char arrays, then strlen() (#include <cstring>). Or if you want to do it yourself , just go through the characters with while loop.
Code:int Length(char* a) { int count = 0; char *aux = a; while (*aux != '\0') { count++; aux++; } return count; }
Or...
int size = sizeof( Array ) / sizeof( char );
where array is the variable name and char is the type of
data stored in your array.