write a function for strtok()??
Answers were Sorted based on User's Feedback
Answer / 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 |
strtok() function is used for tokanizing the given string.
The output of the following program will be as follows.
How|are|you|I|am|Fine.
#include<stdio.h>
int main()
{
char *p;
char str[40]="How are you,I am Fine";
p=strtok(str," ");
printf("%s",p);
do
{
p=strtok('\0',", ");
if(p)
printf("|%s",p);
}while(p);
printf("\n");
}
Is This Answer Correct ? | 4 Yes | 5 No |
Differentiate Source Codes from Object Codes
hi any body pls give me company name interview conduct "c" language only
How do you view the path?
write a program that reads lines(using getline), converts each line to an integer using atoi, and computes the average of all the numbers read. also compute the standard deviation.
What is const keyword in c?
Explain what will the preprocessor do for a program?
c program to manipulate x=1+3+5+...+n using recursion
pascal triangle program
How we can insert comments in a c program?
write a program that eliminates the value of mathematical constant e by using the formula e=1+1/1!+1/2!+1/3!+
what is the defrenece between structure and union
why use "return" statement a) on executing the return statement it immediately transfers the control back to the calling program b) it returns the value present in the parentheses return, to the calling program c) a & b d) none of the above