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

来源:互联网 发布:淘宝自动秒杀软件 编辑:程序博客网 时间:2024/04/28 06:37

 

任务:把"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.wmv456.wmv789.wmvmv.wmvProcess returned 0 (0x0)   execution time : 0.094 sPress any key to continue.