strtok in c 2b 2b

Solutions on MaxInterview for strtok in c 2b 2b by the best coders in the world

showing results for - "strtok in c 2b 2b"
Francesca
19 Jan 2017
1#include <string.h>
2#include <stdio.h>
3
4int main () {
5   char str[80] = "This is - www.tutorialspoint.com - website";
6   const char s[2] = "-";
7   char *token;
8   
9   /* get the first token */
10   token = strtok(str, s);
11   
12   /* walk through other tokens */
13   while( token != NULL ) {
14      printf( " %s\n", token );
15    
16      token = strtok(NULL, s);
17   }
18   
19   return(0);
20}
Mathias
02 Nov 2019
1//The strtok() function in C++ returns the next token in a null terminated byte string.
2#include <cstring>
3#include <iostream>
4using namespace std;
5int main()
6{
7    char str[] = "parrot,owl,sparrow,pigeon,crow";
8    char delim[] = ",";
9    cout << "The tokens are:" << endl;
10    char *token = strtok(str,delim);
11    while (token)
12    {
13        cout << token << endl;
14        token = strtok(NULL,delim);
15    }
16    return 0;
17}
similar questions
queries leading to this page
strtok in c 2b 2b