C String Functions

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:

  1. strlen(): Calculates the length of a string by counting the number of characters before the null terminator.
size_t strlen(const char *str);
  1. strcpy(): Copies the contents of one string to another.
char *strcpy(char *dest, const char *src);
  1. strcat(): Concatenates (appends) one string to the end of another.
char *strcat(char *dest, const char *src);
  1. strcmp(): Compares two strings and returns an integer indicating their relationship.
int strcmp(const char *str1, const char *str2);
  1. strncmp(): Compares a specific number of characters from two strings.
int strncmp(const char *str1, const char *str2, size_t n);
  1. strchr(): Searches for the first occurrence of a character in a string.
char *strchr(const char *str, int c);
  1. strstr(): Searches for the first occurrence of a substring within a string.
char *strstr(const char *haystack, const char *needle);
  1. sprintf(): Formats a string by printing formatted data into a buffer.
int sprintf(char *str, const char *format, ...);
  1. 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.