How do I write a function to split and return an array for a string with delimiters in the C programming language?
char* str = "JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC";
str_split(str,',');
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use the
strtok()function to split a string (and specify the delimiter to use). Note thatstrtok()will modify the string passed into it. If the original string is required elsewhere make a copy of it and pass the copy tostrtok().EDIT:
Example (note it does not handle consecutive delimiters, “JAN,,,FEB,MAR” for example):
Output: