Wednesday, 14 July 2010

String Handling Functions

String Handling Functions are predefined functions which are used to manipulate the strings.
It is also called as "Character Handling Functions"

These functions are defined in "string.h"  Header file. Hence, you must include string.h header file in your program to use these functions.

Method         Description
strcat()          It is used to concatenate(combine) two string
strlen()          It is used to show length of a string
strrev()          It is used to show reverse of a string
strcpy()         Copies one string into another
strcmp()        It is used to compare two string

strcat() function

strcat("hydera","bad");
strcat() function will add the string "hydera" to "bad". i.e Hyderabad

strlen() function

strlen() function will return the length of the string passed to it.
int j;
j=strlen("raj");
printf("%d",j);
output :
3

strcmp() function
strcmp() function will return the ASCII difference between first un matching character of two strings.

#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
int j,k;
j=strcmp("hi","hi");
k=strcmp("Raj","endra");
printf("Hi=Hi%d\n",j);
printf("Raj and endra %d\n",k);
getch();
}
output:
Hi==Hi 0
Raj and endra=-19




Previous


You may like the following posts:
Functions
Arrays
Strings

No comments:

Post a Comment