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 |
what is level of tree if leaf node is at level 4.please explain.
An array name contains base address of the array. Can we change the base address of the array?
what is difference b/w extern & volatile variable??
Given a valid 24 hour format time find the combination of the value and write a program ,do not hard the value and if any other inputs provided should work with the logic implemented Input: 11:30 Output: 13:10 Input: 18:25 Output: 21:58
how can i get output the following... 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 and 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 plz plz...
`write a program to display the recomended action depends on a color of trafic light using nested if statments
How can I change their mode to binary?
The C language terminator is a.semicolon b.colon c.period d.exclamation mark
What does double pointer mean in c?
What is the use of ?: Operator?
1. Write the function int countchtr(char string[ ], int ch); which returns the number of times the character ch appears in the string. Example, the call countchtr(“She lives in NEWYORK”, ‘e’) would return 3.
Write a simple code fragment that will check if a number is positive or negative.