Answers for "strtok in c++"

C++
11

strtok

#include <string.h>
#include <stdio.h>

int main () {
   char str[80] = "This is - www.tutorialspoint.com - website";
   const char s[2] = "-";
   char *token;
   
   /* get the first token */
   token = strtok(str, s);
   
   /* walk through other tokens */
   while( token != NULL ) {
      printf( " %s\n", token );
    
      token = strtok(NULL, s);
   }
   
   return(0);
}
Posted by: Guest on May-15-2020
0

strtok in c++

//The strtok() function in C++ returns the next token in a null terminated byte string.
#include <cstring>
#include <iostream>
using namespace std;
int main()
{
    char str[] = "parrot,owl,sparrow,pigeon,crow";
    char delim[] = ",";
    cout << "The tokens are:" << endl;
    char *token = strtok(str,delim);
    while (token)
    {
        cout << token << endl;
        token = strtok(NULL,delim);
    }
    return 0;
}
Posted by: Guest on June-05-2021

Browse Popular Code Answers by Language