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 |
send me the code of flow chart generator using C-programming language amd this code should calculate the time and space complexity of the given progran and able to generate flowchart according to the given program?
What are reserved words?
Whether there can be main inside another main?If so how does it work?
What are the features of c language?
what is link list?
In c programming typeing to occupy the variables in memory space. if not useing the variable the memory space is wasted.ok, how to avoid the situation..? (the variable is used & notused)
What is #include called?
palindrome for strings and numbers----Can anybody do the prog?
6 Answers CTS, TCS, Vipro Lifescience Pvt,
what does " calloc" do?
The operation of a stair case switch best explains the a) or operation b) and operation c)exclusive nor operation d)exclusive or operation Which of the following is/are syntactically correct? a) for(); b) for(;); c) for(,); d) for(;;);
1 Answers HCL, Public Service Commission,
What is a structure and why it is used?
what is c programing