Language/C
[C] strtok
퓨림노
2012. 12. 10. 10:09
[C] strtok
void main()
{
char name[20];
strcpy( name, "babo aaa bbb ccc ddd eee");
char *p;
p = strtok( name, " ");
if(p)
cout << p << endl;
while( p!= NULL ){
//p = strtok( NULL, " " );
// loop
for( int i=0; i<3; i++ )
p = strtok( NULL, " " );
if( p)
cout << p << endl;
}
}
// 2014.12.21 추가내용
아래의 블로그 참조
- strtok : http://tapito.tistory.com/314
void main()
{
char mystr[256] = { 0, };
char index[20] = {0,};
char ext[10] = {0,};
char delimiters[8] = "L_.";
strcpy(mystr, "L7000_104118101.jpg");
char *tp1 = strtok(mystr, delimiters);
for(;;){
if( tp1 == NULL )
break;
else
printf("strtok : %s\n", tp1);
tp1 = strtok(NULL, delimiters);
}
cout << "org String " << mystr << endl;
}
결과화면