C语言简单实现字符串截取

#include 
#include 
#include 

typedef char T[64];

void mySplit( char *sStr,  char *delims, T t[])
{
    int i = 0;
    char *result = NULL;
    result = strtok( sStr, delims );

    while( result != NULL ) {
        strcpy(t[i++], result);
        printf( "result is [%s] \n", result );
         result = strtok( NULL, delims );
    }

}

int main()
{
    int i=0;
    T t[10];
    char *str = "1231,432,234,542,311,fasa";
    char *dot = ",";
    mySplit(str, dot, t);

    for(i=0; i < 10; i++)
    {
        printf("\t%s\n", t[i]);
    }
    printf("\n");
    return 0;
}

你可能感兴趣的:(C/C++)