字符串截取

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>

//字符串截取strtok会破坏源字符串,用替换截取的标志位

int main0101()

{

  char ch[]="www.itcast.cn";

  char*p=strtok(ch,".");//wwwitcast.cn

  printf("%s ",p);//www

  p=strtok(NULL,".");//wwwitcastcn

  printf("%s ",p);//itcast

  p=strtok(NULL,".");

  printf("%s ",p);//cn

  

  return EXIT_SUCCESS;

}

int main0102(void)

{

  char ch[]="123456@qq.com";

  char str[100]={0};

//字符串备份

  strcpy(str,ch);

  

  char*p=strtok(str,"@");

  printf("%s ",p);//123456

  

  p=strtok(NULL,"."); 

  printf("%s ",p);//qq

  

  return 0;

}

int main(void)

{

  //char ch[] = "nichousha chounizadi zaichouyigeshishi duibuqidagewocuole guawazi ";

  char ch[] = "你瞅啥 瞅你昨地 再瞅一个试试 对不起大哥我错了 瓜娃子 ";

  char*p=strtok(ch," ");

  while(p)

  {

    printf("%s ",p);

    p=strtok(NULL," ");

  }

  return 0;

//结果

}

原文地址:https://www.cnblogs.com/wanghong19991213/p/13616442.html