In this post, we'll learn how to get the length of a string in C.
Thankfully, C provides us with a function called strlen() that does exactly what we need. The function is included with the standard library, inside the <string.h> header file.
First, let's define a string. Remember that a string in C is just an array of characters.
CLIKE
char greeting[] = "Hello, world!";
Now, let's get the length of the string:
CLIKE
char greeting[] = "Hello, world!";
int length = strlen(greeting);
Then if you want, you can print the length using printf: