-
Difference between revisions of "Functions HI-TECH C STRCAT"
(Created page with "<strong>STRCAT, STRCMP, STRCPY, STRLEN et. al.</strong> ==SYNOPSIS== #include <string.h> char * strcat(char * s1, char * s2); int strcmp(char * s1, char * s2); char...") |
m |
||
Line 23: | Line 23: | ||
terminating it. <strong>Strlen</strong>() returns the length of s1, not | terminating it. <strong>Strlen</strong>() returns the length of s1, not | ||
including the terminating null. <strong>Strncat</strong>(), <strong>strncmp</strong>() | including the terminating null. <strong>Strncat</strong>(), <strong>strncmp</strong>() | ||
− | and <strong>strncpy() will catenate, compare and copy s2 and s1 | + | and <strong>strncpy</strong>() will catenate, compare and copy s2 and s1 |
in the same manner as their similarly named counterparts above, but involving at most n characters. For | in the same manner as their similarly named counterparts above, but involving at most n characters. For | ||
<strong>strncpy</strong>(), the resulting string may not be null terminated. | <strong>strncpy</strong>(), the resulting string may not be null terminated. |
Latest revision as of 00:03, 1 August 2017
STRCAT, STRCMP, STRCPY, STRLEN et. al.
SYNOPSIS
#include <string.h> char * strcat(char * s1, char * s2); int strcmp(char * s1, char * s2); char * strcpy(char * s1, char * s2); int strlen(char * s); char * strncat(char * s1, char * s2, size_t n); int strncmp(char * s1, char * s2, size_t n); char * strncpy(char * s1, char * s2, size_t n);
DESCRIPTION
These functions provide operations on null-terminated strings. Strcat() appends the string s2 to the end of the string s1. The string at s1 will be null terminated. Needless to say the buffer at s1 must be big enough. Strcmp() compares the two strings and returns a number greater than 0, 0 or a number less than 0 according to whether s1 is greater than, equal to or less than s2. The comparision is via the ascii collating order, with the first character the most significant. Strcpy() copies s2 into the buffer at s1, null terminating it. Strlen() returns the length of s1, not including the terminating null. Strncat(), strncmp() and strncpy() will catenate, compare and copy s2 and s1 in the same manner as their similarly named counterparts above, but involving at most n characters. For strncpy(), the resulting string may not be null terminated.