String Library Functions

String Library Functions

Published by: Nuru

Published date: 21 Jun 2021

String Library Functions Photo

String Library Functions

String Library Functions are those functions in C, which has some useful contribution for functioning and working of the strings. Some of the string handling functions are strcpy ( ), strcmp ( ), strlen ( ), strcat ( ), etc.

Let us see the working of some of the string functions.

  • Concatenating two strings: strcat
  • String scanning Operation: strchr
  • Copying strings: strcpy
  • Getting string length: strlen
  • Comparison between two strings: strcmp
  • Concatenating the one part of a string with other: strncat
  • Copying the two parts of strings: strncpy
  • Comparison between two parts of strings: strncmp

We use these library functions to manipulate the string data. One can call these functions from the header file namely string.h file.
Some of the string functions are briefly discussed below:

  • Copying the string

We use strcpy ( ) function is used to copy the one string into another one. Another function strncpy ( ) is used for the copying of one part of the string to the other.
The following given program can illustrate the use of the copying string.

String Library Functions

Output:

String Library Functions

 

  • Finding the length of the string

The length of the string is the number of characters present in the string excluding the null character. To find the length of the given string, we use strlen ( ) function.
Syntax: integer_variable = strlen (input_string);

Let us see a program for it:

String Library Functions

Ouput:

String Library Functions

 

  • Concatenation of two Strings

We already know that there is the use of string function strcat ( ) for concatenating two strings. It links or joins the two strings together.
For Instance, let us see a program below:

String Library Functions

 

Output:

String Library Functions

 

 

  • Converting a string to uppercase

Like other functions, for the conversion of string from lower to upper case, there is a library function that is strupr ( ). This converts the given lower case string to the upper case.
For Instance:

String Library Functions

 

Output:

String Library Functions

 

  • Conversion of a Given string to lowercase

The process of conversion to lowercase is also the same method. But, the library function we use here is, strlwr ( ). It converts the uppercase string into the lower case.
For Example:

String Library Functions

Output:

String Library Functions

 

These are some of the library functions of String variables.