Followers

Tuesday, June 13, 2023

Commonly used String functions in the C language

 

Here is a list of commonly used string functions in the C language, which are part of the standard C library <string.h>:

  1. strcpy(): Copies the contents of one string to another.
  2. strncpy(): Copies a specified number of characters from one string to another.
  3. strcat(): Concatenates (appends) one string to the end of another.
  4. strncat(): Concatenates a specified number of characters from one string to another.
  5. strcmp(): Compares two strings and returns an integer indicating their relationship.
  6. strncmp(): Compares a specified number of characters from two strings and returns an integer indicating their relationship.
  7. strlen(): Calculates the length of a string (excluding the null character).
  8. strchr(): Searches for the first occurrence of a specified character in a string and returns a pointer to it.
  9. strrchr(): Searches for the last occurrence of a specified character in a string and returns a pointer to it.
  10. strstr(): Searches for the first occurrence of a specified substring in a string and returns a pointer to it.
  11. strtok(): Breaks a string into smaller tokens based on a delimiter.
  12. strcpy_s(), strncpy_s(), strcat_s(), strncat_s(): More secure versions of the respective functions, designed to prevent buffer overflows.
  13. strdup(): Creates a new string by duplicating an existing string.
  14. strpbrk(): Searches a string for any of a set of specified characters and returns a pointer to the first occurrence.
  15. strspn(): Calculates the length of the initial segment of a string that consists of only the characters specified in another string.
  16. strcspn(): Calculates the length of the initial segment of a string that consists of none of the characters specified in another string.
  17. strcoll(): Compares two strings using locale-specific rules.
  18. strerror(): Returns a string describing the error code passed as an argument.
  19. strtok_r(): Thread-safe version of strtok(), supporting multiple concurrent tokenising operations.

These functions provide a wide range of capabilities for manipulating and working with strings in the C language. Each function serves a specific purpose, allowing you to perform tasks such as copying, concatenation, comparison, searching, tokenising, and more.

No comments:

Post a Comment