write a code for which input is a string and set of characters acting as delimiters. Cut the given string where ever delimiters occur and return all the set of sub strings. For eg: given string abbcdeffghujsb and delimiter set:c,g,j hen output should be: abb, deff, u, sb
Answer goes as belowchar delimiter[] = {'c', 'j' , 'f'};
void get_sub_str(const char *str, char *dl, int dn)
{
char temp[1024];
int i, j, len = 0;
int ssu = 0; // sub string update
for(i=0; str[i]!='\0'; i++)
{
for(j=0; j<dn; j++)
{
if( str[i] == dl[j])
ssu = 1;
}
if(ssu == 1)
{
temp[len] = '\0';
printf("%s\n", temp);
len = 0;
ssu = 0;
i++;
}
temp[len] = str[i];
len++;
}
}
No comments:
Post a Comment