Question: c program 1 - WAP to implement strtok function Description: Read string1 and string2 from user. Call my_strtok (string1, string2); Should treat string2 as delimitter

c program

1 - WAP to implement strtok function

Description:

Read string1 and string2 from user.

Call my_strtok (string1, string2);

Should treat string2 as delimitter in string1 and should return 1 st field.

If you call again my_strtok (NULL, string2), it should return second field in string1 treating string2 as delimitter.

Pr-requisites:-

Storage Classes

Strings

Pointers

Objective: -

To understand the concept of

Strings functions

Inputs: - 2 Strings Sample execution: - Test Case 1: user@emertxe] ./my_strtok Enter string1 : Bangalore;;::---Chennai:;Kolkata:;Delhi:-:Mumbai Enter string2 : ;./-: Tokens : Bangalore Chennai Kolkata Delhi Mumbai Test Case 2: user@emertxe] ./my_strtok Enter string1 : -;Bangalore;;::---Chennai:;Kolkata:;Delhi:- Enter string2 : ;./-: Tokens : Bangalore Chennai Kolkata Delhi

requested file

#include #include #include

char *my_strtok(char str[], const char delim[]);

int main() { char str[50], delim[50]; printf("Enter the string : "); scanf("%s", str); __fpurge(stdout); printf("Enter the delimeter : "); scanf(" %s", delim); __fpurge(stdout); char *token = my_strtok(str, delim); printf("Tokens : "); while (token) { printf("%s ", token); token = my_strtok(NULL, delim); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!