0% found this document useful (0 votes)
56 views6 pages

Wap To Find Length of String Without Using Strlen Function

The document contains code snippets for 3 programs that perform string operations in C++ without using library functions: 1) A program to find the length of a string without using strlen by iterating through the string with a for loop and counting characters. 2) A program to compare two strings using strcmp. 3) A program to concatenate two strings using strcat and output the result.

Uploaded by

Er Natish Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views6 pages

Wap To Find Length of String Without Using Strlen Function

The document contains code snippets for 3 programs that perform string operations in C++ without using library functions: 1) A program to find the length of a string without using strlen by iterating through the string with a for loop and counting characters. 2) A program to compare two strings using strcmp. 3) A program to concatenate two strings using strcat and output the result.

Uploaded by

Er Natish Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

PROGRAM NO 6.

WAP TO FIND LENGTH OF STRING WITHOUT USING STRLEN FUNCTION.

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{
clrscr();
char s1[18];
int i,c=0;
cout<<"Enter the string = ";
gets(s1);
for(i=0;s1[i]!='\0';i++)
{
c++;
}
cout<<"The length of string is = "<<c;
getch();
}
OUTPUT:
PROGRAM NO. 7

WAP TO COMPARE TWO STRINGS .

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{
clrscr();
int j;
char s1[50],s2[50];
cout<<"Enter the 1st string = ";
gets(s1);
cout<<"Enter the 2nd string = ";
gets(s2);
j=strcmp(s1,s2);
if(j==0)
{
cout<<"both strings are equal";
}
else if(j>0)
{
cout<<"s1 is greater than s2";
}
else
{
cout<<"s2 is greater than s1";
}
getch(); }
OUTPUT:

PROGRAM NO. 8
WAP TO CONCATENATE TWO STRINGS.

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{
clrscr();
char s1[50],s2[50];
cout<<"Enter the 1st string = ";
gets(s1);
cout<<"Enter the 2nd string = ";
gets(s2);
strcat(s1,s2);
cout<<"string after concatenation = ";
cout<<s1;
getch();
}
OUTPUT :

You might also like