Standard C Library – String.h  Functions

The C language comes bundled with <string.h> which contains some useful string-handling functions. Some of them are as follows:

Function Name Description
strlen(string_name) Returns the length of string name.
strcpy(s1, s2) Copies the contents of string s2 to string s1.
strcmp(str1, str2) Compares the first string with the second string. If strings are the same it returns 0.
strcat(s1, s2) Concat s1 string with s2 string and the result is stored in the first string.
strlwr() Converts string to lowercase.
strupr() Converts string to uppercase.
strstr(s1, s2) Find the first occurrence of s2 in s1.

Must Read:



Strings in C

A String in C programming is a sequence of characters terminated with a null character ‘\0’. The C String is stored as an array of characters. The difference between a character array and a C string is that the string in C is terminated with a unique character ‘\0’.

Similar Reads

C String Declaration Syntax

Declaring a string in C is as simple as declaring a one-dimensional array. Below is the basic syntax for declaring a string....

C String Initialization

A string in C can be initialized in different ways. We will explain this with the help of an example. Below are the examples to declare a string with the name str and initialize it with “GeeksforGeeks”....

C String Example

C // C program to illustrate strings   #include #include   int main() {     // declare and initialize string     char str[] = "Geeks";       // print string     printf("%s\n", str);       int length = 0;     length = strlen(str);       // displaying the length of string     printf("Length of string str is %d", length);       return 0; }...

Read a String Input From the User

...

How to Read a String Separated by Whitespaces in C?

The following example demonstrates how to take string input using scanf() function in C...

C String Length

...

Passing Strings to Function

...

Strings and Pointers in C

We can use multiple methods to read a string separated by spaces in C. The two of the common ones are:...

Standard C Library – String.h  Functions

...