Answer Posted / manya
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
char * __mstrtok(char *str, char *delimiters)
{
int i;
char map[32];
char *dlmt = delimiters;
char *s1,*s2;
static char *laststr;
for(i=0;i<32;i++)
map[i] = 0;
for(;*dlmt;dlmt++)
map[*dlmt >> 3] |= 1 << (*dlmt & 7);
if(str)
s1 = str;
else
s1 = laststr;
if(!s1)
return NULL;
if(map[*s1 >> 3] & 1 << (*s1 & 7))
s1++;
s2 = s1;
for(;*s1;s1++)
{
if(map[*s1 >> 3] & 1 << (*s1 & 7))
{
*s1++ = '\0';
laststr = s1;
return s2;
}
}
return NULL;
}
int main()
{
char *token;
char string[] = "Hi friend, how are you? How is life! going
on, right.";
for(token=__mstrtok(string," ,?!.");
token;
token=__mstrtok(NULL," ,?!."))
printf("|%s|",token);
printf("\n Done \n");
return 0;
}
| Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
the 'sizeof' operator reported a larger size than the calculated size for a structure type. What could be the reason?
Is there any algorithm to search a string in link list in the minimum time?(please do not suggest the usual method of traversing the link list)
How many types of errors are there in c language? Explain
What is difference between scanf and gets?
Explain which function in c can be used to append a string to another string?
what is the diffrenet bettwen HTTP and internet protocol
How can you tell whether two strings are the same?
Write a program to print factorial of given number without using recursion?
What’s a signal? Explain what do I use signals for?
the maximum length of a character constant can be a) 1 character b) 8 characters c) 256 chaacters d) 125 characters
Why do we write return 0 in c?
Explain how do you generate random numbers in c?
What are the keywords in c?
What is the difference between printf and scanf )?
What is data structure in c programming?