0
1.6kviews
Explain any 2 functions of string.h

Mumbai University> FE > Sem 2> STRUCTURED PROGRAMMING APPROACH

Marks: 4 M

Year: Dec 2016

1 Answer
0
9views

strcat:

This library function concatenates a string onto the end of the other string.

If a and b are 2 strings and want to concatenates (join) them the use strcat(a,b) this syntax replace string a with new string which is joined a and b.

program:

#include<stdio.h>
#include<conio.h>
main()
{
char str1[10] = "Happy";
char str2[10] = "Diwali";
strcat(str1,str2);
printf(“The concatenated string is %s”,str1);
getch();
}

Output:
The concatenated string is HappyDiwali

strlen This library function returns the length of a string.

If string a has 6 characters then strlen(a) returns value 6.

Program:

#include<stdio.h>
#include<conio.h>
main()
{
char str1[10] = "Happy";
char str2[10] = "Diwali";
int len1,len2;
len1=strlen(str1);
len2=strlen(str2);
printf(“The Length of string 1 is %d”,len1);
printf(“The Length of string 2 is %d”,len2);

getch();
}

Output:
Length of string 1 is 5
Length of string 2 is 6
Please log in to add an answer.