zoukankan      html  css  js  c++  java
  • strtok

    1、

    Int main(void)

    {

    char *tmp = NULL;

    Char *remotebuf=”0 ”;

    tmp = strtok(remotebuf, DELIM);      执行出现段错误。

    }

    2、

    Int main(void)

    {

    char *tmp = NULL;

    char *remotebuf = NULL;

    remotebuf = (char *)malloc(10);

    strcpy(remotebuf, "0 ");

    tmp = strtok(remotebuf, DELIM);      执行则没有问题。

    }

    3、

    Int main(void)

    {

    Char *remotebuf=”0 ”;

    Printf(“%s ”,remotebuf);      执行没有问题

    }                            

    vi strtok

    #include<string.h>

    #include<stdio.h>

    int main(void)

    {

            char *p,coname[20]=":name:name1",*colon=":",*name;

            printf("%s ",coname);

            p=strtok(coname,colon);

            printf("%s ",p);

            printf("%s ",coname);

            name=strtok(NULL,colon);

            printf("%s ",name);

            return 0;

    }

    root@dbaudit-desktop:~/xcj# gcc -o strtok strtok.c

    root@dbaudit-desktop:~/xcj# ./strtok

    :name:name1

    name

    :name

    name1

    当strtok()在参数s的字符串中发现参数delim中包涵的分割字符时,则会将该字符改为 字符。因此第一次和第二次打印coname结果不同,数组默认结尾是。。

    因此使用char *strtok(char s[], const char *delim);函数之前,要先把s拷贝出来一份。

    如果有一天我们淹没在茫茫人海中,庸碌一生,那一定是我们没有努力活得丰盛
  • 相关阅读:
    集群技术
    Docker Swarm(一)
    服务器集群
    生产环境swarm集群规划和管理
    集群的分类
    Arcengine C#开发源码
    BIOS设置中开启cpu睿频功能
    aida64怎么用?aida64最详细的使用教程
    SQL Server2019最大并行度
    IIS 之 在IIS7、IIS7.5中应用程序池最优配置方案
  • 原文地址:https://www.cnblogs.com/xiachj/p/4112096.html
Copyright © 2011-2022 走看看