In the previous post we learn about what is String.we know that string is a collection of two or more characters.In string we can store alphabet, digit and special symbols.
In this post we will learn what are the string functions.
This function is used to copy the source string into target string.
Syntax: strcpy(target string, source string);
Example:
type first string: programming
second string: programming
2.strlen ( ):
This function is used to find out the length of the string.
Syntax: strlen(string name);
3.strcmp ( );
This function is used to compare two strings.if both values are equal then it will return zero.if first string is greater than second string it return value greater than zero.if the value is less than zero then it is case sensitive.
Syntax: strcmp(string1,string2);
4.strcat():
This function appends means add second string at the end of first string.
Syntax: strcat(string1,string2);
5.strrev():
This function reverse contents of the given string and store it again in the same variable.
Syntax: strrev(string);
In this post we will learn what are the string functions.
String functions:
1.strcpy ( ):This function is used to copy the source string into target string.
Syntax: strcpy(target string, source string);
Example:
void main() { char stirng1[10],string[20]; clrscr(); printf("type first stirng"); scanf("%s",string1); strcpy(string2,string1); printf("second string=%s",string2"); }
Output:type first string: programming
second string: programming
2.strlen ( ):
This function is used to find out the length of the string.
Syntax: strlen(string name);
3.strcmp ( );
This function is used to compare two strings.if both values are equal then it will return zero.if first string is greater than second string it return value greater than zero.if the value is less than zero then it is case sensitive.
Syntax: strcmp(string1,string2);
4.strcat():
This function appends means add second string at the end of first string.
Syntax: strcat(string1,string2);
5.strrev():
This function reverse contents of the given string and store it again in the same variable.
Syntax: strrev(string);