c言語でカンマ区切りの文章を読む

c言語でカンマ区切りの文章を読む
http://simd.jugem.jp/?eid=49
http://networkprogramming.blog18.fc2.com/blog-entry-89.html

strtok関数で空白で分ける。
strtok関数は、
strtok(文字列,区切り文字)の仕様。



一回目はstrok(文字列, 区切り文字)で呼ぶ。
二回目はstrok(NULL,区切り文字)で呼ぶ。
区切るものがなくなったらNULLを返す。


連続するカンマは扱えないので注意。

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

 int main(){

         using namespace std;

         //char str[]="a b c d e";

         char str[]="a b c d e";
         char *token;

         for(token=strtok(str," ");token!=NULL;token=strtok(NULL," ")){
                 printf("%s\n",token);
         }

 }