C Strings | String Functions in C Language

C Strings

C strings is nothing but an array of characters (OR char data types). that is terminated by \0 (null character).

String in/output:

string.h : Collection of functions for string manipulation.

C Strings | C Language
C Language | Strings in C | Tech-Mirror

There are two ways to declare string in c language.

  1. By string literal
  2. By character array

Let’s see the example of declaring string by literal.

In this case, ‘\0′(null character) will be appended at the end of string by the compiler.

We can also define string by character array.

Array index always starts from 0 and in above case it will be 0 to 10.

While declaring a string, size of string is not mandatory. So we can write the above code as given below:

String Example in C Language

Output :

Reading And Writing Strings Using gets and puts

Output :

String Functions in C Language | String Manipulation Functions in C

The nine most commonly used functions in the string library are as follows:

Function Name Description
strlen It is Used to get string length
strchr String scanning operation
strcpy Copy a string
strcmp Compare two strings
strcat Used for Concatenation of two strings
strncpy Copy part of a string
strncat Concatenate one string with part of another
strncmp Compare parts of two strings
strrchr string scanning operation

For More C Arrays

Leave a Reply

Your email address will not be published. Required fields are marked *