String Functions in C

For Complete YouTube Video: Click Here

In this class, we will understand String Functions in C.

We have already discussed the concepts of strings.

String Functions in C

The string functions are pre-defined whose functionalities were written in the “strings. h” header file.

Pre-defined functions are those whose functionalities are defined by the compiler designers.

In this class, we will discuss some of the string functions, and the remaining string functions are here.

strlen function

strlen(string name): returns the length of the string name.

char s[16] = “Learning Monkey”;
printf(“%d”, strlen(s));

strcpy function

strcpy(destination, source): copies the contents of the source string to the destination string.

char s[16] = “Learning Monkey”;
char d[16];
strcpy(d, s);

strcat function

strcat(first-string, second-string): concats or joins first string with the second string. The result of the ‘string is stored in the first string.

char f[16] = “Learning Monkey”;
char s[16] = “Learn for FREE!”;
strcat(f, s);

strcmp function

strcmp(first-string, second-string): compares the first string with the second string. If both ‘the strings’ are the same, it returns 0.

char f[40] = “Learning Monkey”;
char s[16] = “Learn for FREE!”;
if(strcmp(f, s) == 0)
{
printf(“Same Strings”);
}
else
{
printf(“Different Strings”);
}