Thursday, 12 December 2013

Program of string operations(length,concat and compare) without using the built in functions.

/*Program of string operations(length,concat and compare) without using the built in functions.*/

#include<iostream>

#include<string.h>
#include<conio.h>
using namespace std;
int main()
{
        char str[100],str1[100];
        int i=0,ch=1,icnt=0,icnt2=0,flag=0;

        

                cout<<"\nPlease enter a string:";
                cin>>str;
                cout<<endl<<"----LENGHT----"<<endl;
                
                //Length calculation
                while(str[i++]!='\0')
                {
                        icnt++;
                       
                }
                cout<<"\nThe given string contains "<<icnt<<" character(s) "<<endl;
                cout<<endl<<"----STRING COMPARE----"<<endl;
                cout<<"\nPlease enter string 2:";
                cin>>str1;
                i=0;

                //String comparision

                while(str1[i++]!='\0')
                {
                        icnt2++; 
                }
                for(i=0;str[i]!='\0';i++)
                        {
                                if(str[i]==str1[i])
                                        flag=1;
                                else
                                {
                                        cout<<"\nStrings are not equal";
                                        flag=0;
                                        break;
                                }

                        }

                if(flag==1)
                        cout<<"\nBoth strings are equal"<<endl;
                
                cout<<endl<<"----CONCATINATION----"<<endl;
                
                //String Conctination
                
                for(i=0;i<icnt2;i++)
                {
                        str[icnt++]=str1[i];                               
                }
                str[icnt]='\0';
                cout<<"\nThe concatinated string is "<<str;

               getch();

}



OUTPUT





No comments:

Post a Comment