#include "stdafx.h" #include <string.h> #include <stdio.h> 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 Tokens: ", strtemp ); trim(szResult,strtemp,seps); printf( "result:%s(ok!) ", 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 ", token ); strcat(desc,token); /* Get next token: */ token = strtok( NULL, seps ); } return desc; } |