字符串分割处理,strstr函数应用

 

任务:把"123.wmv\n456.wmv\n789.wmv\nmv.wmv"这串字符串分割成一系列*.wmv输出

#include <stdio.h>
#include <string.h>

int main()
{
    char *List[100];
    char spath[60]="123.wmv\n456.wmv\n789.wmv\nmv.wmv";
    char *ps = spath;
    char *needle="\n";
    char* buf = strstr( ps, needle);
    int i = 0;
    char **pList;
    pList=List;

    while( buf != '\0' )
    {
        buf[0]='\0';
        List[i] = (char*)malloc(4);
        strcpy(List[i],ps);
        ps = buf + strlen(needle);
        buf = strstr( ps, needle);
        printf("%s\n",*(pList+i));
        i++;
    }
    List[i] = (char*)malloc(4);
    strcpy(List[i],ps);
    printf("%s\n",*(pList+i));
}


output:

123.wmv
456.wmv
789.wmv
mv.wmv

Process returned 0 (0x0)   execution time : 0.094 s
Press any key to continue.


 

你可能感兴趣的:(list,任务,output)