How to count a character...
Example:
char char1[20] = "love";
result is countchar = 5;
The result is base on how many the char is in the char1.
char1 have 5 char including the null terminator which turn countchar equal to 5.
How to count a character...
Example:
char char1[20] = "love";
result is countchar = 5;
The result is base on how many the char is in the char1.
char1 have 5 char including the null terminator which turn countchar equal to 5.
A homework question?
byte CountString( const char *c_Str )
{
byte b_Return = 0;
while( c_Str[ b_Return ] != '\0' ) ++b_Return;
return b_Return;
}
char char1[20] = "love";
byte countchar = CountString( char1 ) + 1;
The number of useful characters in the array is not 5. It's 4.
Google would have probably steered you in the right direction if you had search for "string length".
Of course, you really should have a book about C programming, since it is the foundation for C++ programming. And, that book would certainly have had a reference to the strlen() function that would have eliminated the need to recreate it.
khizon18:
How to count a character...
It's a complex question all right. Thankfully Mr. Google invented the solution.
http://lmgtfy.com/?q=c+string+length
Only 16 million results.