Easy Tutorial
❮ C Exercise Example66 C Examples Hcf Gcd ❯

C Standard Library - <string.h>

Introduction

The string.h header file defines a variable type, a macro, and various functions for manipulating character arrays.

Library Variables

Here are the variable types defined in the string.h header file:

No. Variable & Description
1 size_t <br>This is an unsigned integer type, which is the result of the sizeof keyword.

Library Macros

Here are the macros defined in the string.h header file:

No. Macro & Description
1 NULL <br>This macro is the value of a null pointer constant.

Library Functions

Here are the functions defined in the string.h header file:

No. Function & Description
1 void *memchr(const void *str, int c, size_t n) <br>Searches for the first occurrence of the character c (an unsigned char) in the first n bytes of the string pointed to by the argument str.
2 int memcmp(const void *str1, const void *str2, size_t n) <br>Compares the first n bytes of str1 and str2.
3 void *memcpy(void *dest, const void *src, size_t n) <br>Copies n characters from src to dest.
4 void *memmove(void *dest, const void *src, size_t n) <br>Another function to copy n characters from src to dest.
5 void *memset(void *str, int c, size_t n) <br>Copies the character c (an unsigned char) to the first n characters of the string pointed to by the argument str.
6 char *strcat(char *dest, const char *src) <br>Appends the string pointed to by src to the end of the string pointed to by dest.
7 char *strncat(char *dest, const char *src, size_t n) <br>Appends the string pointed to by src to the end of the string pointed to by dest, up to n characters long.
8 char *strchr(const char *str, int c) <br>Searches for the first occurrence of the character c (an unsigned char) in the string pointed to by the argument str.
9 int strcmp(const char *str1, const char *str2) <br>Compares the string pointed to by str1 to the string pointed to by str2.
10 int strncmp(const char *str1, const char *str2, size_t n) <br>Compares up to n characters of the string pointed to by str1 to the string pointed to by str2.
11 int strcoll(const char *str1, const char *str2) <br>Compares the string pointed to by str1 to the string pointed to by str2, depending on the LC_COLLATE setting.
12 char *strcpy(char *dest, const char *src) <br>Copies the string pointed to by src to dest.
13 char *strncpy(char *dest, const char *src, size_t n) <br>Copies up to n characters from the string pointed to by src to dest.
14 size_t strcspn(const char *str1, const char *str2) <br>Calculates the length of the initial segment of str1 which consists entirely of characters not in str2.
15 char *strerror(int errnum) <br>Searches an internal array for the error number errnum and returns a pointer to an error message string.
16 size_t strlen(const char *str) <br>Computes the length of the string str up to but not including the terminating null character.
17 char *strpbrk(const char *str1, const char *str2) <br>Searches the string str1 for the first occurrence of any character from the string str2, not including the terminating null character.
18 char *strrchr(const char *str, int c) <br>Searches for the last occurrence of the character c (an unsigned char) in the string pointed to by the argument str.
19 size_t strspn(const char *str1, const char *str2) <br>Calculates the length of the initial segment of str1 which consists entirely of characters in str2.
20 char *strstr(const char *haystack, const char *needle) <br>Searches for the first occurrence of the string needle (not including the terminating null character) in the string haystack.
21 char *strtok(char *str, const char *delim) <br>Splits the string str into tokens separated by delim.
22 size_t strxfrm(char *dest, const char *src, size_t n) <br>Transforms the first n characters of the string src into the current locale and places them in the string dest, based on the LC_COLLATE setting.
❮ C Exercise Example66 C Examples Hcf Gcd ❯