cstring functions

    • (Remember that strcmp() is tricky! It returns 0 when the strings are the SAME, >0 if str1 is greater, or <0 if str2 is greater)

strtok()

Description

The C library function char *strtok(char *str, const char *delim) breaks string str into a series of tokens using the delimiter delim.

Declaration

Following is the declaration for strtok() function.

char *strtok(char *str, const char *delim) 

Example:

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

int main()
{
   char str[80] = "This is, - www.CS262.com! - website";
   const char s[15] = " !-,.";
   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);
}

Result:
This is www CS262 com website
 

猜你喜欢

转载自www.cnblogs.com/JasperZhao/p/12914706.html