write a function for strtok()??

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


Please Help Members By Posting Answers For Below Questions

What are the types of data types and explain?

659


There is a practice in coding to keep some code blocks in comment symbols than delete it when debugging. How this affect when debugging?

802


Are c and c++ the same?

620


Can you please explain the difference between strcpy() and memcpy() function?

589


What is getch?

622






How can my program discover the complete pathname to the executable from which it was invoked?

650


How can a process change an environment variable in its caller?

645


Are comments included during the compilation stage and placed in the EXE file as well?

660


#define f(g,h) g##h main O int i=0 int var=100 ; print f ("%d"f(var,10));} wat would be the output??

1531


Explain 'far' and 'near' pointers in c.

692


I need a help with a program: Write a C program that uses data input in determining the whole of points A and a whole of circles B. Find two points in A so that the line which passes through them, cut through the maximum number of circles.

1485


Why doesnt long int work?

600


write a program to reverse a every alternetive words in a string in a place. EX: Input is "this is the line of text" Output should be "shit is eht line fo text" Please any one tell me code for that.

1564


FILE *fp1,*fp2; fp1=fopen("one","w") fp2=fopen("one","w") fputc('A',fp1) fputc('B',fp2) fclose(fp1) fclose(fp2)} a.error b. c. d.

1185


What is the importance of c in your views?

583