![]() |
In C, strings are arrays of characters using string manipulation often requires splitting a string into substrings based on multiple delimiters. In this article, we will learn how to split a string by multiple delimiters in C. Example Input: Split a String into Words by Multiple Delimiters in CTo split a string by multiple delimiters in C, we can use the strtok() function from the standard library. This function allows us to specify multiple delimiters and iteratively extract tokens from the string by calling this function in a loop to get all tokens and when there are no more tokens it returns NULL otherwise, returns the pointer to the first token encountered in the string. Syntax to Use strtok Function in Cchar *strtok(char *str, const char *delims); Here,
C Program to Split a String by Multiple DelimitersThe following example demonstrates how to split a given string by multiple delimiters in C.
Output Hello World This is GeeksForGeeks Time complexity: O(n) |
Reffered: https://www.geeksforgeeks.org
C Language |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 19 |