String manipulation

Home / C Programming / String manipulation

String manipulation


String manipulation in C involves performing various operations on strings, such as concatenation, copying, searching, and tokenization. C provides a set of standard library functions to handle string manipulation. Below are some commonly used string manipulation functions in C:

String Length:

To find the length of a string, you can use the strlen() function.


String Copy:

To copy one string to another, you can use the strcpy() function.


String Concatenation:

To concatenate two strings, you can use the strcat() function.


String Comparison:

To compare two strings, you can use the strcmp() function. It returns 0 if the strings are equal, a negative value if the first string is lexicographically less than the second one, and a positive value if it's greater.


Searching a Substring:

To search for a substring within a string, you can use the strstr() function.


These are some of the basic string manipulation functions in C. Remember to include the <string.h> header to use these functions as they are part of the C standard library. Additionally, be cautious about buffer overflows and ensure that you have enough space allocated for the destination strings when performing manipulations.