String handling library.

                          String handling library

This is the theoretical blog dealing with various string handling library.These are the inbuilt function available in c language.We will discuss each one of them .


                       
        

                             Various string handling library:

    1) strlen():
                          This is the inbuilt function available in c language.It is used in finding the                                    length of string.It is found in    <string.h>   header file. Below is the simple                              code explaining the strlen() function.                                                                                                                                                                                                                                                                                   #include<stdio.h>
                             #include<conio.h>
                             #include<string.h>
                             #include<stdlib.h>
                              void main()
                              {
                                   clrscr();
                                   char str1[30];
                                   int len=0;
                                   printf("Enter string\n");
                                   gets(str1);
                                   len=strlen(str1);
                                   printf("%d",len);
                                   getch();
                              }

  
    2)strcpy();
                          This inbuilt function copy one string into other string.It is also available in                                            <string.h>  header file.
                         
        
                                 #include<stdio.h>
                                 #include<conio.h>
                                 #include<string.h>
                                 #include<stdlib.h>
                                 void main()
                                 {
                                     clrscr();
                                     char str1[30],str2[30];
                                     printf("Enter string\n");
                                     gets(str1); 
                                     strcpy(str2,str1);
                                     printf("%s",str2);
                                     getch();
                                 }
      3)strcat():
                        This inbuilt fuction concatenates two string.It basically join two string.It is also                                    available in <string.h> header file.
                             
                                #include<stdio.h>
                                #include<conio.h>
                                #include<string.h>
                                #include<stdlib.h>
                                void main()
                                {
                                    clrscr();
                                    char str1[]="This is ",str2[]="my computer";
                                    strcat(str1,str2);
                                    puts(str1);
                                    puts(str2);
                                    getch();
                                }


       4)strcmp(): 
                           This in built function compare two string.It is also available in <string.h> header                               file.
                           

                               #include<stdio.h>
                               #include<conio.h>
                               #include<stdlib.h>
                               #include<string.h>
                               void main()
                               {
                                     clrscr();
                                     char str1[]="123",str2[]="123;
                                     int option;
                                     option=strcmp(str1,str2);
                                     if(option==0)
                                      {
                                           printf("Both string are equal\n");
                                       }                                  
                                   else
                                         {
                                                printf("Both string are not equal\n");
                                          }
                                      getch();
                              }


         5)strrev():
                                This inbuilt function just reverse the string.For example  it will reverse 123
                                to 321.This is also available in  <string.h> header file.

                                 
                                   #include<stdio.h>
                                  #include<conio.h>
                                  #include<string.h>
                                  #include<stdlib.h>
                                  void main()
                                  {
                                        clrscr();
                                        char str[]="Computer";
                                        strrev(str);
                                        puts(str);
                                        getch();
                                  }


                                              
               
                
                             
                          
                          
                                       



                
String handling library. String handling library. Reviewed by Deepak kumar soni on December 28, 2018 Rating: 5

No comments:

Powered by Blogger.