分类: C/C++
2008-08-07 17:37:38
#include "stdafx.h" #include下载本文示例代码#include char seps[] = " "; char* trim(char* desc,char* src,char* seps); int main(int argc, char* argv[]) { char szResult[1024]=""; memset(szResult,0,1024); char strtemp[]="ab c d e f"; printf( "%s\n\nTokens:\n", strtemp ); trim(szResult,strtemp,seps); printf( "result:%s(ok!)\n", szResult ); return 0; } ////////////////////////////////////////////////////// char* trim(char* desc,char* src,char* seps) { char* token=NULL; /* Establish string and get the first token: */ token = strtok(src, seps); while( token != NULL ) { /* While there are tokens in "string" */ printf( " %s\n", token ); strcat(desc,token); /* Get next token: */ token = strtok( NULL, seps ); } return desc; }