C String Functions

In this tutorial, you will learn about manipulating strings. As C compiler supports a large set of string library functions. You can any of the library functions in order to manipulate the strings. Here, you will learn to get a string from the user and perform operations on the string. You can choose any of the string functions according to the need of the problem. It is even possible to solve the problem using the manual process without using the string functions. But in doing so the program will increase the size and complexity of the program. We can define all the string functions under the standard library “string.h”.

Following are the most commonly used string functions. All the string functions are defined individually in detail below.

strlen():

Strelen() functions are the functions which are used to calculate the length of the strings. Here, the length of the string means the total number of characters in the string including the spaces.

C program to calculate the length of a string using C string Functions(link left to be copied)

strlwr():

In C language we can use strlwr() function for converting any string into its corresponding lower case letters. Following is the syntax of the srtrlwr() function.

Syntax:

strlwr(variable);

Look at the following example by clicking on the link below. This example below will help to make you understand more about the implementation of strlwr() function.

C program to the convert the character of the given string into its corresponding lowercase format

strupr():

We can use the function strupr() for converting the characters of any given string into its corresponding uppercase format.
Syntax:

strupr(variable);

The above function returns the uppercase format of the given string. Now, see the following example to understand more about the strupr() function through its implementation.

C program to the convert the character of the given string into its corresponding uppercase format

strcpy()

strcpy() is a library function for doing an operation in C. This function will copy the content of one string into another string.

The syntax of the strcpy() function is given below.

Syntax:

strcpy(variable 2, variable 1);

Now click the link below to understand the implementation of strcpy() fucntion.

C program to copy the elements of one string to the another

strcmp()

This function compares two strings and finds out whether they are same or not. The strcmp() function compares two strings character by character until there is a mismatch or then end of one string. If two strings are identical, this function will return the numeric difference between the ASCII value of first non-matching pair characters.

The following example will make you more clear of this function. Click on the link below.

C program to compare two strings

strcat()

This function helps to concatenate any two strings in the program. It will concatenate two strings into a single string and returns the concatenated string. The syntax of this function is given below.

Syntax:

strcat(string1, string2)

Now, look at the example implementing the strcat() function by clicking on the link below.

C Program to concatenate two strings

strrev()

The function strrev() is used to print the reverse of the given string. The syntax for this function is given below.

Syntax:

strrev(“string”);

Now see the example below to understand more by clicking on the link below.

C program to print the reverse of the string

C program to check whether a given string is palindrome or not

SHARE C String Functions

Leave a Reply

Your email address will not be published.

Share