know yourselves. information, computer, 7 wonders, various.

Sunday, November 12, 2017

C++ programming language part: 41 Standard String-Handling function


Standard String-Handling function

strcpy()

The strcpy() function is used to copy the content of second string to first string. second string must be a pointer to a null-terminated string. The strcpu() function returns a pointer to the end of first string.

Program 30
{
              char a1[10],a2[10];
              cout<<"Type a string "<
              cin>>a1;
              cout<<"Type another string "<
              cin>>a2;
              cout<
              }

strcat()

The strcat() function work the same as the strcpy() function except that the characters from the second string are copied onto the end of the first string. 




Program 31
         {               char a1[10],a2[10];
              char x[20];
              cout<<"Type a string "<
              cin>>a1;
              cout<<"Type another string "<
              cin>>a2;
              //x=strcat(a1,a2);
              cout<
               //cout<
             
Note:Mind it that  the second string would be the same.You can do also cout<

Exercise: Make some program by using strcat(a1,"Nova") or (strcpy(a1, "Hello")

strcmp()
The strcmp() function compares two string and returnes an integer value, what is the ASCII value.

Program 32
           { char a1[10],a2[10];
              int x;
              cout<<"Type a string "<
              cin>>a1;
              cout<<"Type another string "<
              cin>>a2;
              x=strcmp(a1,a2);
              cout<
strlen()

This function returns the number of characters in the string passed to it. The length does not include the NULL character.

Program 33
         {   char a1[10],a2[10];
              int len1;
              int len2;
              int sum;
              cout<<"Type a string "<
              cin>>a1;
              cout<<"Type another string "<
              cin>>a2;
              len1=strlen(a1);
              len2=strlen(a2);
              sum=len1+len2;
              char *p;
              p=a1+len1-2;  // last two letters   
             cout<<"The length of two string is "<
            cout<< "The last two letters of furst string is "<

Note: The file string.h should be included as a header file

Exercise: 1. Write a program to compare two stringusing string handle

                2. Write a program to marge two stringusing string handle


Part- 86 assign the content of twostring



জ্ঞানকোষ প্রকাশনী
৩৮/২-ক, বাংলাবাজার (২য় তলা), ঢাকা।
       ফোনঃ ৭১১৮৪৪৩, ৮১১২৪৪১, ৮৬২৩২৫১.         
                                                     
কলকাতায় পরিবেশক/প্রাপ্তিস্থান
রিতা ইন্টারন্যাশনাল
৩৬, পি.এন. ব্যানার্জি রোড, কলকাতা
ফোনঃ ২৫১৩৮৩৫৯, ৯৮৩০৪৩৯৬৭৯, +৯১৯৮৩০৪৩৯৬৭৯