String Functions: by Team-1 Prasanna A Alka Mary Abraham Minimol T K Jacob Tisson
String Functions: by Team-1 Prasanna A Alka Mary Abraham Minimol T K Jacob Tisson
By Team-1
Prasanna A
Alka Mary Abraham
Minimol T K
Jacob Tisson
Strcat()
SYNTAX
char *strcat(char *dest, const char *src);
DESCRIPTION
strcat() is used to concatenate a null-terminated string to end of
another string variable.
DESCRIPTION
The strncat() function appends up to n characters from
string s2 to string s1 and then appends a terminating null
character.
The initial character of s2 overwrites the null character at
the end of s1.
Subsequent characters in s2 are appended to s1 until either
the end of s2 is reached or n characters have been copied.
DESCRIPTION OF Strncat()
The function strncat() does not allocate any storage. The caller must
insure that the buffer pointed to by s1 is long enough to hold the added
characters.
Example
#include <stdio.h>
int main()
{
char string1[20];
char string2[20];
strcpy(string1, "Hello");
strcpy(string2, "Hellooo");
printf("Returned String : %s\n", strncat(string1,string2,4));
printf("Concatenated String : %s\n", string1 );
return 0;
}
Output
Returned String : HelloHell
Concatenated String : HelloHell
Strchr()
SYNTAX
char *strchr(const char *s, int c);
DESCRIPTION
if (pos)
printf("Character ‘a' is found at position %d.\n", pos+1);
else
printf("Character ‘a’ is not found.\n");
return 0;
}
Output
Character ‘a' is found at position 4.
Size_t strspn()
SYNTAX
DESCRIPTION
The strspn() function computes the length of the maximum initial
segment of the string s1 that consists entirely of characters from the
string s2.
Its purpose is to determine the size, location, and existence of strings
in memory.
The strspn() function returns the index of the first character in str1
that doesn't match any character in str2.
EXAMPLE: