A practical tutorial on how to find the length of a string in C
usestrlen()
Provided functionsCStandard librarystring.h
head File.
char name[7] = "Flavio";
strlen(name);
This function returns the length of the string as an integer value.
Working example:
#include <string.h>
#include <stdio.h>
int main(void) {
char name[7] = "Flavio";
int length = strlen(name);
printf("Name length: %u", length);
}
Download mine for freeC manual
More clang tutorials:
- Introduction to C programming language
- C variables and types
- C constant
- C operator
- C conditional
- How to use loops in C
- Introduction to C arrays
- How to determine the length of an array in C
- Introduction to C strings
- How to find the length of a string in C
- C pointer introduction
- Iterate over the array in C
- Boolean in C
- Introduction to C functions
- How to use NULL in C
- Basic I/O concepts in C language
- Double quotes and single quotes in C
- How to return a string from a C function
- How to solve the implicit declaration library function warning in C language
- How to check character value in C
- How to use `printf()` to print percent characters in C language
- C conversion specifiers and modifiers
- How to access command line parameters in C
- Range of variables in C
- Can functions be nested in C?
- Static variables in C
- C global variables
- Typedef keyword in C language
- C enumeration type
- C structure
- C header file
- C preprocessor