Strlen Strcpy
Total Page:16
File Type:pdf, Size:1020Kb
Strlen Description The strlen() function shall compute the number of bytes in the string to which s points, not including the terminating null byte. Return value The strlen() function shall return the length of s; the function has no failure mode and no error return. Prototype Declared in string.h size_t strlen(const char *s); Strcpy Prototype Declared in string.h In C90, the prototype is: char *strcpy(char *dest, const char *src); The C99 prototype is identical but adds the new restrict qualifiers: char *strcpy(char * restrict dest, const char * restrict src); Description The strcpy() function shall copy the null-terminated string pointed to by src to the memory pointed to by dest. Source and destination may not overlap. Return value The strcpy() function shall return the pointer dest; the function has no failure mode and no error return. Strcat Description The strcat() function shall append the null-terminated string pointed to by src to the null-terminated string pointed to by dest. The first character of src overwrites the null-terminator of dest. Source and destination may not overlap. Return value The strcat() function shall return the pointer dest; the function has no failure mode and no error return. Prototype Declared in string.h In C90, the prototype is: char *strcat(char *dest, const char *src); Strcmp Description The strcmp() function compares the string pointed to by s1 to the string pointed to by s2. Return value The strcmp() function returns an integer greater than, equal to, or less than zero, accordingly as the string pointed to by s1 is greater than, equal to, or less than the string pointed to by s2. Prototype Declared in string.h The C89/C99 prototype is: int strcmp(const char * s1, const char * s2); Strchr Description The strchr() function locates the first occurrence of c (converted to a char) in the string pointed to by s. The terminating null character is considered to be part of the string. Return value The strchr() function returns a pointer to the located character, or a null pointer if the character does not occur in the string. Prototype Declared in string.h The C89/C99 prototype is: char *strchr(const char *s, int c); .