strsep的用法

strsep的用法一 出现段错误看下面两种写法 1 nbsp include includestruc nbsp nbsp nbsp charname 32 nbsp nbsp nbsp char value nbsp nbsp nbsp structitem next intmain nbsp nbsp nbsp char channel start end nbsp nbsp nbsp structitemte

一.出现段错误

看下面两种写法

1.

 

#include


#include

struct item
{

    char name[32];
    char *value;
    struct item *next;
};

int main()
{

    char *channel,*start,*end;
    struct item test;

    snprintf(test.name,31,”%s”, “channel”);
    test.value = (char *)malloc(128);
    snprintf(test.value,127,”%s”,”1-15,17-31,43,55″);
   
    if(!strcasecmp(test.name,”channel”))
    {

        while(channel = strsep(&test.value,”,”))
        {

            start = strsep(&channel,”-“);
            if(channel)
            {

                end = channel;
                printf(“include channel start from %s to %s/n”,start,end);
            }
            else
                printf(“include channel %s/n”,start);
        }
    }

    return 0;
}






































 

 

2.写法2

 

#include


#include

struct item
{

    char name[32];
    char value[128];
    struct item *next;
};

int main()
{

    char *channel,*start,*end;
    struct item test;

    snprintf(test.name,31,”%s”, “channel”);
    //test.value = (char *)malloc(128);
    snprintf(test.value,127,”%s”,”1-15,17-31,43,55″);
   
    if(!strcasecmp(test.name,”channel”))
    {

        while(channel = strsep(&test.value,”,”))
        {

            start = strsep(&channel,”-“);
            if(channel)
            {

                end = channel;
                printf(“include channel start from %s to %s/n”,start,end);
            }
            else
                printf(“include channel %s/n”,start);
        }
    }

    return 0;
}






































 

段错误

 

二.下面的段错误

 

#include


#include

int main(void)
{

   char *p,*str = “asd@123”; //old
 
  

printf(“len = %d/n”,strlen(str));
printf(“str = %c/n”,str[4]);
printf(“11/n”) ;
str[3]=’a’ ; //err
strcpy(str,”/0″) ; //err
printf(“len = %d/n”,strlen(str));
printf(“str = %c/n”,str[0]);

return 0;
}



















 

三strsep的一个示例

 

#include


#include

int main()
{

    char *ip = “192.168.0.1”;
    char *tmp, *p;
    tmp = ip;
   
    tmp = (char *)malloc(100) ;
    strcpy(tmp,ip) ;
    //strncpy(tmp,99,ip)
    while((p = strsep(&tmp, “.”)) != NULL)
    {

        printf(“%s/n”, p);
    }
}

















 

 

 

 

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/217513.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月18日 上午9:24
下一篇 2026年3月18日 上午9:24


相关推荐

  • windows下如何安装git及配置环境_git安装失败

    windows下如何安装git及配置环境_git安装失败下载安装1.从git官网下载一个git安装包,官网下载地址http://www.git-scm.com/download/2.双击安装程序(如果没有SecurityWarning请跳过此步骤),请点击【Run>】3.阅读协议,点击【Next>】4.选择安装位置,点击【Next>】5.选择安装组件:这里可以使用默认选项,点击【Next…

    2025年10月2日
    7
  • vsftp搭建_安装vsftpd

    vsftp搭建_安装vsftpd2016-05-29回答首先在client上建立publickey和privatekey,需要使用ssh-keygen命令[root@localhost.ssh]#ssh-keygen–trsageneratingpublic/privatersakeypair.enterfileinwhichtosavethekey(/root/.ssh/id_rsa…

    2026年3月4日
    5
  • 作用域插槽的使用(四个作用域的区别)

    什么是作用域插槽?其实就是带数据的插槽。父组件可以通过绑定数据传递给子组件,而作用域插槽可以通过子组件绑定数据传递给父组件。作用域的使用场景:既可以复用子组件的slot,又可以使slot内容不一致!代码如下:<divid=”app”><div><emp-list:emps=”empList”><templateslot=”emp”slot-scop..

    2022年4月15日
    70
  • MIME类型是什么?包含哪些类型?

    MIME类型是什么?包含哪些类型?MIME 类型是什么 MIME Multipurpose 多用途互联网邮件扩展类型 是设定某种扩展名的文件用一种应用程序来打开的方式类型 当该扩展名文件被访问的时候 浏览器会自动使用指定应用程序来打开 MIME 类型有哪些 常用 Mime 类型 文件后缀 Mime 类型说明 flvflv flv flash 在线播放 ht

    2026年3月16日
    2
  • 软件测试理论试题及答案

    软件测试理论试题及答案一 选择题 一分一题共 45 分 下列软件属性中 7 软件产品首要满足的应该是 A A 功能需求 B 性能需求 C 可扩展性和灵活性 D 容错纠错能力软件缺陷产生的原因是 D A 交流不充分及沟通不畅 软件需求的变更 软件开发工具的缺陷 B 软件的复杂性 软件项目的时间压力 C 程序开发人员的错误 软件项目文档的缺乏 D 以上都是导致软件缺陷的最大原因是

    2026年3月19日
    2
  • AI编程实战:用OpenClaw在30分钟内搭建龙虾识别系统

    AI编程实战:用OpenClaw在30分钟内搭建龙虾识别系统

    2026年3月13日
    3

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号