Wednesday, September 5, 2018

String Library Function in C Language for BCA Sem - 1 and PGDCA Sem - 1


---------------------------------------------------------------------------------------------------------------------
Prepared By : Uday Shah (HOD-IT)
Contact No : 7600044051
E-Mail : rupareleducation@gmail.com


String Library Function

Strcpy
Copies all most characters of src to dest

Declaration:
     char *strcpy(char *dest, const char *src);

Remarks:
     Copies string src to dest, stopping after the terminating null character has been moved.


strncpy
Copies at most max length characters of src to dest

Declaration:
     char *strncpy(char *dest, const char *src, size_t maxlen);
    
Remarks:
     strncpy copies up to maxlen characters from src into dest,      truncating or null-padding dest. _fstrncpy is the far version.

     The target string, dest, might not be null-terminated if the length of src
     is maxlen or more.


strcat
Appends one string to another

Declaration:
char *strncat(char *dest, const char *src, size_t maxlen);

Remarks:
     strncat copies at most maxlen characters of src to the end of dest and      then appends a null character.



strchr
Scans a string for the first occurence of a given character

Declaration:
char *strchr(const char *s, int c);

Remarks:
strchr scans a string in the forward direction, looking for a specific character.

strrchr
Finds the last occurrence of c in s

Declaration:
char *strrchr(const char *s, int c);

Remarks:
strrchr scans a string in the reverse direction, looking for a specific character.

strcmp
strcmp compare two strings
int strcmp(const char *s1, const char*s2);

Remarks:
The string comparison starts with the first character in each string and continues with subsequent characters until the corresponding characters differ or until the end of the strings is reached.

To use strcmp, you must include STRING.H. This macro is provided for compatibility with other C compilers.

strncmp
strncmp compare portions of two strings. strncmpi is a macro compares portions of two strings, without case sensitivity

Declaration:
int strncmp (const char *s1, const char *s2, size_t maxlen);



Remarks:
Each of these routines compares s1 to s2, looking at no more than maxlen characters.


The string comparison starts with the first character in each string and continues with subsequent characters until the corresponding characters differ or until maxlen characters have been examined.

To use strncmp, you must include STRING.H.




strcspn
strcspn scan a string for a segment that DOES NOT contain a subset of a set of characters. strspn scan a string for a segment that is a subset of a set of characters

Declaration:
size_t strcspn(const char *s1, const char *s2);

Remarks:

strcspn find the initial segment of string s1 that consists entirely of characters NOT from string s2.

Strlen
Calculates length of a string

Declaration:
size_t strlen(const char *s);
    
Remarks:
strlen calculates the length of s.

Return Value:
Returns the number of characters in s, not counting the terminating null





strpbrk
Scans one string for the first occurrence of any character that is in a second string

Declaration:
char *strpbrk(const char *s1, const char *s2);

Remarks:
strpbrk scans a string, s1, for the first occurrence of any character appearing in s2.





strstr
Finds the first occurrence of a substring in another string

Declaration:
char *strstr(const char *s1, const char *s2);

Remarks:
strstr scan s1 for the first occurrence of the substring s2.On success, strstr returns a pointer to the element in s1

strtok
Scans s1 for the first token not contained in s2

Declaration:
char *strtok(char *s1, const char *s2);

Remarks:
strtok consider the string s1 to consist of a sequence of zero or more text tokens, separated by spans of one or more characters from the separator string s2.

The first call to strtok
*  returns a pointer to the first character of the first token in s1, and
*  writes a null character into s1 immediately following the returned token.


Best Of Luck