2016-06-01 10 views
-1

이 문자는 ab, 83 및 de의 세 부분으로 가져오고 싶습니다. 하지만 마지막 공간 다음에 공백과 2 개의 숯 사이에 숯을 얻는 방법을 모르겠습니다. 어떻게하는지 말해줘. 당신이일부 문자를 공백으로 구분하는 방법

void main() 
{ 
    char input[12]="ab 83 de"; 
    char *p; 
    p = strtok(input," "); 

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

http://stackoverflow.com/questions/236129/split-a-string-in-c – Mat

+1

이유 'strtok'의 인수에 공백이 두 개 있습니까? –

+2

코드 출력 :'ab' (개행)'83' (개행)'de' (개행) http://ideone.com/lWLqqJ는 당신이 원하는 것이 아닙니까? –

답변

1

당신이 사용할 수있는 감사 std::istringstreamoperator>>과 :

istringstream iss("ab 83 de"); 
string str; 
while (iss >> str) { 
    // process with str 
} 

LIVE

관련 문제