String length without string handling function
In this example, we will understand to perform string operations like string length without using string handling function and know how to write, compile and debug it in C language and also learn how to implement it in c.
As you know the best way to do this program is by using the strlen() function but in this example we do it manually without using any string handling function
In order to do this you will need
- Basic knowledge of c programming language.
- As well as know how to operate codeblocks.
So let's begin with our program
1.Open a codeblocks software.
2.Open new empty file.
3.Copy and paste the code from below.
Input code-
//program to perform string operations like string length without using string handling function
#include<stdio.h>
int main()
{
char s[10];
int i,lenght=0;
printf("Enter a string:");
scanf("%s",s);
for(i=0;s[i]!='\0';i++)
{
lenght=lenght+1;
}
printf("Lenght of string:%d",lenght);
return 0;
}
Now simply build the code. Look for any error. Now run the code.
For output enter any number or character series you want and press enter key.
Click the following button to download a program to perform string operations like string length without using string handling function
Thats it.Thank you for scrolling.
Tags:
string handling function