TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Monday 25 May 2020

String Library Function In C Language | String Library Function In C Programming Language | String Library Function In C Language With Example

String Library Function In C Language


In this header file string  related  header file are include  and function definition are store in it, in this character group are include and there are different type function are available on it. C Support a large number  of string  handling function  in the standard  library String.h.


Example:

Strcat(), strcmp(), strrev(),  strupr(),  strlen(), strlwr(), strcpy().


image of String Library Function In C Language
Fig: String Library Function
 


1.    Strcat()

Concatenates(join) two strings


Synatx:

Strcat (str1,str2);


Program

#include<iostream.h>

#include<conio.h>

#include<string.h>

void main()

{

char     a[20];

cout<<”Input your name”;

strcpy(a,  “pramod”);

strcat( a,  “dwivedi”);

cout<< a;

getch();

}


Output:

Input your name

Pramoddwivedi


2.strlen()

Computes string’s length.


Syntax :

Variable name= strlen(string);


Program:

#include<iostream.h>

#include<conio.h>

#include<string.h>

void main()

{

char     a1[20],  a2[20];

int len1,len2;

cout<<”Input Value”;

cin>>a1;

cin>>a2;

len1=strlen(a1);

len2=strlen(a2);

cout<<len1;

cout<<len2;

getch();

}


Output:

Input Value

Pramod

Dwivedi

6    7

 

3.strcpy()

Copies a string  to  another.


Program:

#include<iostream.h>

#include<conio.h>

#include<string.h>

void main()

{

char     str2[]={dwivedi};

char   str1[20];

strcpy(str1, str2);

cout<<str1;

cout str2;

getch();

}


Output:

Dwivedi

Dwivedi


4. strcmp()

Compare two String.


Syntax:

Variable name= strcmp(str1, str2);


Program

#include<iostream.h>

#include<conio.h>

#include<string.h>

void main()

{

int     s;

char     a1[20];

char     a2[30];

cout<<”input String”;

cin>>a1;

cin>>a2;

s=strcmp(a1,a2);

getch();

}


Output:

Input String

Pramod

Ram

9


5.strlwr()

Convert string to lowercase.


Syntax:

Strlwr(string name);


Program:

#include<iostream.h>

#include<conio.h>

#include<string.h>

void main()

{

char     a[20];

cout<<“Input String”;

cin>>a;

strlwr(a);

cout<<a;

getch();

}


Output:

Input  String

PRAMOD

pramod


6.strupr()

Converts into uppercase.


Syntax:

Strupr(string name);


Program:

#include<iostream.h>

#include<conio.h>

#include<string.h>

void main()

{

char     a[20];

cout<<“Input String”;

cin>>a;

strupr(a);

cout<<a;

getch();

}


Output:

Input  String

pramod

PRAMOD


7. strrev()

Converts string to reverse .


Syntax:

Strrev(string name);


Program:

#include<iostream.h>

#include<conio.h>

#include<string.h>

void main()

{

char     a[20];

cout<<“Input String”;

cin>>a;

strrev(a);

cout<<a;

getch();

}


Output:

Pramod

domap

 

 

 

 

 

 


No comments:

Post a Comment