Saturday, September 26, 2020

Explain string function with example.1]strcmp(), 2] strupr(), 3]strlwr(), 4]strrev(), 5]strstr(), 6]strset().


1] strcmp() function : 

▪️ This function compares two strings to find out whetherthey are same ordifferent.

▪️ If two strings are found identitcal, this function returns zero "0", otherwise returns a numeric difference between ASCII valueof non matching characters.

▪️ The general form of strcmp() is

             I=strcmp(str1,str2);

Example:

#include<stdio.h>

#include<string.h>

void main()

{

     int i ;

     char s1[15]="Mrug garud",s2[15]="Mrug kolhekar";

     i = strcmp(s1, s2);

     if(i == 0)

      {

           printf(" two strings are same");

       }

else

       {

           printf( " two strings are different");

       }

}

2] strupr() function:

▪️ Thisfunction converts the caracters of string variable to upper case.

▪️ The general format of strupr() is

              Strupr(string);

Example:

#include<stdio.h>

#include<string.h>

void main()

{

    char name [15]="akash";

    strupr(name);

    printf("Enter your good name=%s",name);

}

▪️ Output:

            Enter you good name= AKASH

3] strlwr() function:

▪️ This function convers the character of string variable to lower case.

▪️ The general form of strlwr() function is

                 strlwr (string);

Example:

#include<stdio.h>

#include<string.h>

void main()

{

     char str[10]="AKASH";

     strlwr(str);

     printf("New string=%s",str);

}

Output:

New caracter string = akash

4] strrev() function:

▪️ This function reverses the characters of string variable.

▪️ The general form of strrev() function is

                strrev(string);

Example:

#include<stdio.h>

#include<string.h>

void main()

{

    char str[10]="MRUGNAYANI";

    strrev(str);

    prntf("New strig=%s",str);

}

Output:

New string=INAYANGURM

5] strstr() function:

▪️ This is a two parameter function that can be used to locate a sub string in a string.

▪️ The general form of strstr() function is

              i = strstr(string,substring)

Example:

#include<stdio.h>

#include<string.h>

void main()

{

     char str[30]="how are you friends";

     int i;

     i=strstr(str, "are");

     if(i==null)

     {

           printf("string is not found");

     }

else

     {

          printf(" strig is found ");

     }

}

Output:

         string is found

6] strset() function:

▪️ The function is used to set all characters of a string to the given character.

▪️ The general form of strset() function is

              strset(string, character);

Example:

#include<stdio.h>

#include<string.h>

void main()

{

     char str[10]=" sky ";

     strset(str, 'x');

     printf(" New string = %s ",str);

}

Output:

New string = x x x



      

3 comments:

  1. This theme bis not adjustable with smartphone so please set responsive theme for your blog
    My link
    https://vcarskill2020.blogspot.com/2020/09/kia-sonet-review.html?m=1
    https://vcarskill2020.blogspot.com/2020/09/kia-sonet-review.html?m=1

    ReplyDelete

Object Paradigm Oriented Programming in C++ / object oriented programming / History of C++/ paradiagram in c++/C devolop, Operating System, Unix operating system, Assembly language, popular in world, Programming language.

  Object Paradigm Oriented Programming  Two programmers, Brian Kernighan and Dennis Ritchie developed a new language called C, in 1972.  C l...