String Manipulations in C Programming Using Standard Library Function

In this tutorial, you will learn about string manipulations in c programming using standard library functions.

string manipulation in c

String manipulations in C

C supports a string handling library which provides useful functions that can be used for string manipulations.

All these string handling functions are defined in the header file string.h. So every time we use these string handling functions string.h header file must be included. Some of the major string handling functions used are tabulated below.

Function

Work

strcat( ) concatenates two strings
strlen( ) finds the length of string
strcpy( ) copies one string in to another another string
strcmp( ) compares two strings
strlwr( ) converts string to lowercase
strupr( ) converts string to uppercase
strstr( ) finds first occurrence of substring in string
strtok( ) splits strings into tokens

[adsense1]

 

Function strcpy copies its second argument into its first argument and we must ensure that array is large enough to store strings of second arguments and a null character.

Function strcmp compares its first and second arguments character wise. It returns 0 if the strings are equal.
It returns a positive value if the first string is greater than second.
It returns a negative value if the first string is less than second.

Function strlen returns the length of input string. It does not include a null character in the length of the string.

puts( ) and putchar( ) function


This both function are defined in input/output library stdio.h and are used for manipulating string and character data.

Syntax of putchar

int putchar( int x );

This will print the character stored in x and returns it as an integer.

Syntax of puts

puts("\nHello World!!!");

This will print “Hello World!!!”.