Lengths of strings
#include <stdio.h>
void main() {
char str1[40] = "To be or not to be";
char str2[40] = ",that is the question. ";
int count = 0;
while (str1[count] != '\0')
count++;
printf("\nThe length of the string \"%s\" is %d characters.", str1, count);
count = 0;
while (str2[count] != '\0')
count++;
printf("\nThe length of the string \"%s\" is %d characters.\n", str2, count);
}
Related examples in the same category