![]() |
A string in C is an array that stores a sequence of characters terminated by a NULL character. In this article, we will learn how to calculate the length of a string without using the inbuilt strlen method in C. For Example, Input: str= "Hello, world!" Find the Length of String without strlen in CTo find the length of a string, we generally use the strlen() function provided in the <string.h> header. But we can also find the length of the string simply by using a loop to iterate through a given string and keep counting the characters until the null terminator(‘\0’) is encountered.
C Program to Find Length of String without strlen FunctionC
Output
The length of the string is: 13 Time Complexity: O(N), where N is the number of character in the string excluding NULL character. |
Reffered: https://www.geeksforgeeks.org
C Language |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |