String handling using library functions in Data Structure using C

In C, you can use various library functions in the `string.h` library to handle strings. Here are some examples of commonly used string handling functions:

1. `strlen()`: This function returns the length of a string.

```
char str[100] = "Hello";
int len = strlen(str); // len is 5
```

2. `strcpy()`: This function copies one string to another.

```
char str1[100] = "Hello";
char str2[100];
strcpy(str2, str1); // str2 is now "Hello"
```

3. `strcat()`: This function concatenates two strings.

```
char str1[100] = "Hello";
char str2[100] = " world!";
strcat(str1, str2); // str1 is now "Hello world!"
```

4. `strcmp()`: This function compares two strings and returns an integer value indicating their relationship.

```
char str1[100] = "Hello";
char str2[100] = "Hello";
int result = strcmp(str1, str2); // result is 0
```

5. `strchr()`: This function searches a string for a specific character and returns a pointer to its first occurrence.

```
char str[100] = "Hello, world!";
char* ptr = strchr(str, ','); // ptr points to the comma character
```

6. `strstr()`: This function searches a string for a specific substring and returns a pointer to its first occurrence.

```
char str[100] = "Hello, world!";
char* ptr = strstr(str, "world"); // ptr points to the "world" substring
```

These are just a few examples of the many string handling functions available in the `string.h` library. You can find more information and examples in the C documentation.



About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext