C Program to Find the Length of a String
ADVERTISEMENTS
C program to find the length of a string.
In this article, you will learn how to calculate the length of a given sting.
Example
INPUT: This is my first program
OUTPUT
String Length: 24
Source
// C program to find the Length of a String
#include <stdio.h>
// It's the main function of the program
int main() {
char str[] = "This is my first program";
int i;
// Iterate over the string the count the total characters
for (i = 0; str[i] != '\0'; i++);
// Final output of the progrm
printf("String Length: %d\n", i);
return 0;
}
Output
String Length: 24