String
String
Function Description
strlen() finds the length of string
strcat( ) concatenates two strings
strcmp( ) compares two strings
strcpy( ) copies one string in to another string
strncpy( ) copies up to n characters from the one string to another
strncmp( ) compares at most the first n bytes of two strings
string.h
strlen()
Calculates the length of the string up to but not including the null
character
Syntax:
size_t strlen(const char *str);
size_t- This is the unsigned integral type
str − This is the string whose length is to be found
This function returns the length of string
//Ex: program to Illustrate/Demonstrate strlen()
#include<string.h>
#include<stdio.h>
void main()
{
char str[]="hello";
int len;
len=strlen(str);
printf("The length of the string is:%d\n",len);
}
strcat()
appends the string pointed to by str2 to the end of the string pointed
to by str1
Syntax:
#include<string.h>
#include<stdio.h>
void main()
char str1[20]="hello",str2[7]="World";
strcat(str1,str2);
printf("str1=%s",str1);
}
strcmp()
compares the string pointed to, by str1 to the string pointed to by str2.
syntax
#include<string.h>
#include<stdio.h>
void main()
char str1[20],str2[7]="World";
strcpy(str1,str2);
printf("str1=%s",str1);
}
strncpy()
finds the first occurrence of the substring str2 in the string str1.
The terminating '\0' characters are not compared.
Syntax: