strtok

2018-11-11 16:05 更新

 原型:extern char *strtok(char *s, char *delim);
       
 用法:#include <string.h>
 
 功能:分解字符串為一組標記串。s為要分解的字符串,delim為分隔符字符串。
 
 說明:首次調(diào)用時,s必須指向要分解的字符串,隨后調(diào)用要把s設(shè)成NULL。
       strtok在s中查找包含在delim中的字符并用NULL('\0')來替換,直到找遍整個字符串。
       返回指向下一個標記串。當沒有標記串時則返回空字符NULL。
 
 舉例:


     // strtok.c
     
     #include <syslib.h>
     #include <string.h>
     #include <stdio.h>
     main()
     {
       char *s="Golden Global View";
       char *d=" ";
       char *p;
       
       clrscr();
       
       p=strtok(s,d);
       while(p)
       {
         printf("%s\n",s);
         strtok(NULL,d);
       }
       getchar();
       return 0;
     }      


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號