strtok

char *strtok( char *str, const char *delim )

文字列delimの中の各文字を分離記号として、
文字列strの中からトークンを切り出す。
2回目以降はstrにNULLを指定してstrtokを呼び出す。
戻り値がNULLになるまでstrtokを実行すると、
全てのトークンを得る事ができる。


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

void main()
{
 char s[] = "123,456.789 012/,.:345:678";
 const char delim[] = "/: ,.";
 char *p;

 p = strtok( s, delim );
 printf( "%s\n", p );
 while ( ( p = strtok( NULL, delim ) ) != NULL )
  printf( "%s\n", p );
}


実行結果

123
456
789
012
345
678

C > 標準関数 > 文字列処理関数 | comments (0) | trackbacks (0)

Comments

Comment Form

icons:

Trackbacks