C string functions are a set of predefined functions in the C programming language that are used for manipulating and working with strings. These functions operate on null-terminated character arrays, commonly referred to as C strings.
Here are some commonly used C string functions:
strlen()
: Calculates the length of a string by counting the number of characters before the null terminator.
size_t strlen(const char *str);
strcpy()
: Copies the contents of one string to another.
char *strcpy(char *dest, const char *src);
strcat()
: Concatenates (appends) one string to the end of another.
char *strcat(char *dest, const char *src);
strcmp()
: Compares two strings and returns an integer indicating their relationship.
int strcmp(const char *str1, const char *str2);
strncmp()
: Compares a specific number of characters from two strings.
int strncmp(const char *str1, const char *str2, size_t n);
strchr()
: Searches for the first occurrence of a character in a string.
char *strchr(const char *str, int c);
strstr()
: Searches for the first occurrence of a substring within a string.
char *strstr(const char *haystack, const char *needle);
sprintf()
: Formats a string by printing formatted data into a buffer.
int sprintf(char *str, const char *format, ...);
strtok()
: Breaks a string into a series of tokens based on a delimiter.
char *strtok(char *str, const char *delimiters);
These are just a few examples of C string functions. There are many more available in the C standard library, each serving a specific purpose in manipulating and working with strings.