使用strtok函數解析string類型數據

我們經常要在string字符串數據中提取一些有用的信息。如果字符串信息是以相同的字符分隔開來的話,用strtok是個好方法。

例子如下:

#include <stdio.h>
#include <string.h>
void main(void)
{
   char str[] = "2011-11-21 13:59";
   printf("strtok: '-' ");
   char *psub = strtok(str, "-");
   puts(psub);
   while( psub = strtok(NULL, "-") )
   {
        puts(psub);
   }
}


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章