国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
字符串分割

strsep

  原型:char *strsep(char **stringp, const char *delim);
  功能:分解字符串為一組字符串。
  示例:    
  #include <stdio.h>
  #include <string.h>
  int main(void)
  {
  char str[] = "root:x::0:root:/root:/bin/bash:";
  char *buf;
  char *token;
  buf = str;
  while((token = strsep(&buf, ":")) != NULL){
  printf("%s\n", token);
  }  
  return 0;
  }
 
 
 
 

原型

  char *strtok(char *s, char *delim);

功能

  分解字符串為一組字符串。s為要分解的字符串,delim為分隔符字符串。

說明

  首次調(diào)用時(shí),s指向要分解的字符串,之后再次調(diào)用要把s設(shè)成NULL。
  strtok在s中查找包含在delim中的字符并用NULL('')來替換,直到找遍整個(gè)字符串。
  char * p = strtok(s,";");
  p = strtok(null,";");
  在調(diào)用的過程中,字串s被改變了,這點(diǎn)是要注意的。

返回值

  從s開頭開始的一個(gè)個(gè)被分割的串。當(dāng)沒有被分割的串時(shí)則返回NULL。
  所有delim中包含的字符都會(huì)被濾掉,并將被濾掉的地方設(shè)為一處分割的節(jié)點(diǎn)。

strtok函數(shù)在C和C++語言中的使用

  strtok函數(shù)會(huì)破壞被分解字符串的完整,調(diào)用前和調(diào)用后的s已經(jīng)不一樣了。如果
  要保持原字符串的完整,可以使用strchr和sscanf的組合等。

c

  #include <string.h>
  #include <stdio.h>
  int main(void)
  {
  char input[16] = "abc,d";
  char *p;
  /**/ /* strtok places a NULL terminator
  in front of the token, if found */
  p = strtok(input, ",");
  if (p) printf("%s\n", p);
  /**/ /* A second call to strtok using a NULL
  as the first parameter returns a pointer
  to the character following the token */
  p = strtok(NULL, ",");
  if (p) printf("%s\n", p);
  return 0;
  }

c++

  #include <iostream>
  #include <cstring>
  using namespace std;
  int main()
  {
  char sentence[]="This is a sentence with 7 tokens";
  cout<<"The string to be tokenized is:\n"<<sentence<<"\n\nThe tokens are:\n\n";
  char *tokenPtr=strtok(sentence," ");
  while(tokenPtr!=NULL)
  {
  cout<<tokenPtr<<'\n';
  tokenPtr=strtok(NULL," ");
  }
  cout<<"After strtok, sentence = "<<sentence<<endl;
  return 0;
  }
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
strtok函數(shù)的使用
strstr和strtok函數(shù)
strtok.c函數(shù)
C和指針之字符串strtok函數(shù)
strtok函數(shù)實(shí)現(xiàn)與應(yīng)用
c語言中字符串比較易錯(cuò)的地方
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服