Write a program to find string length in c
BM Balmiki Mandal 19 Sep 2022 1 views 0 comments C Programming

Write a program to find string length in c

Program to Find String Length in C

In C programming, a string is a sequence of characters that is terminated by a null character \0. The length of a string is the number of characters in the string, excluding the null character.

The length of a string is an essential concept in C programming because it is used in many standard library functions that operate on strings. For example, the strlen function is a standard library function in C that returns the length of a string. The strcpy function copies a string from one location to another, and the strcat function concatenates two strings.

Example of a string finding String length in C:

 

This program uses a while loop to count the number of characters in the string str. The loop keeps iterating until it reaches the null character \0, which marks the end of the string. The length variable is incremented each time the loop iterates, so it contains the length of the string when the loop is finished.

C programming

#include
int main()
{
    char s[10];
    int i;
    printf("Enter the string:");
    scanf("%s",s);
    printf("string is: %d\n",s);
    for(i=0;s[i];i++);
    printf("String length is:%d\n",i);
}

Output:

Enter the string: ELECTRO4U
string is: ELECTRO4U
String length is:9

Further Reading:

Concatenating Two Strings in C: A Step-by-Step Guide

Design a function to count given character in given string

Design a function to reverse the given string

Design a function to search given character in given string in c

Design a function to reverse the word in given string

Design a function replace the words in reverse order in a given string line

Design a function to find string length in c

Design a Function to print the string character by character

Enroll Now:

[ C-Programming From Scratch to Advanced 2023-2024] "Start Supercharging Your Productivity!"

Contact Us:

  • For any inquiries, please email us at [info@electro4u.net].
  • Follow us on insta  [ electro4u_offical_ ] for updates and tips.

 

Note: If you encounter any issues or specific errors when running this program, please let me know and I'll be happy to help debug them!

0 Comments

No comments yet, Be the first to comment.

Post a Comment

Please sign in to post a comment.

Related Posts

Bit wise operators Assignment

Bitwise Operators practical assignment: Take runtime input, bit-level manipulation, and different data units r...

AG Anvesh G 27 Sep 2026
Understanding Float and Double Binary Representation in C

Understanding Float and Double Binary Representation in CIntroduction:When we store decimal numbers such as 10...

AG Anvesh G 31 May 2026
Topic-wise C Programming Interview Questions

C Programming Interview Questions – Topic Wise1. IntroductionC programming is one of the most important langu...

AG Anvesh G 30 May 2026