字符串分割处理,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.


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值