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拷贝出来一份。

    如果有一天我们淹没在茫茫人海中,庸碌一生,那一定是我们没有努力活得丰盛
  • 相关阅读:
    关于高等代数的证明题
    关于微小摄动法的专题讨论
    关于数学分析的数学竞赛题
    关于高等代数的数学竞赛题
    关于幂等阵与幂幺阵的专题讨论
    关于幂零阵与秩1阵的专题讨论
    关于可交换阵与数量阵的专题讨论
    关于等价标准形的专题讨论
    css制作圣诞树
    Integer.parseInt() 错误
  • 原文地址:https://www.cnblogs.com/xiachj/p/4112096.html
Copyright © 2011-2022 走看看