Program Discussion :: Basics
213 / 279
Write your own strtok program in c.
Answer:
#include
#include
int main()
{
char str[] = "qqq44in-tttterv-vviieew-www...-...com-mm";
strtoken(str,'-');
//printf("%s",str);
return 0;
}
void strtoken(char *x, char c)
{
char *y = x;
int i = 0, n = 0;
while (*x != '\0')
{
if (*x == c)
{
print(y,x);
y = x+1;
}
x++;
}
}
print(char *x, char *y)
{
while (x
Asked In ::
Language:
Hemanth
31 Mar, 2018 11:05 PM
#include <stdio.h>
#include <string.h>
int main()
{
char str[] = "qqq44in-tttterv-vviieew-www...-...com-mm";
strtoken(str,'-');
//printf("%s",str);
return 0;
}
void strtoken(char *x, char c)
{
char *y = x;
int i = 0, n = 0;
while (*x != '\0')
{
if (*x == c)
{
print(y,x);
y = x+1;
}
x++;
}
}
print(char *x, char *y)
{
while (x<y)
{
printf("%c",*x);
x++;
}
printf("\n");
}