关闭

c - strtok / strrchr

标签: c语言
106人阅读 评论(0) 收藏 举报
分类:
#include<string.h>
#include<stdio.h>

int 
main(int argc, const char *argv[])
{
    char input[16]="abc,d,ef,gh";
    char *p;
    /*strtok places a NULL terminator
    infront of the token,if found*/
    p = strtok(input,",");
    while (p != NULL)
    {
        printf("%s\n", p);
        p = strtok(NULL,",");
    }
    return 0;
}
#include <string.h>
#include <stdio.h>

int
main (int argc, const char *argv[])
{
    char input[16] = "a,b,c,d,e";
    char *p;

    p = strrchr(input, ',');
    if (p) {
        printf("Last token: %s\n", p + 1);
    }
    return 0;
}

References

  1. http://linux.die.net/man/3/strtok
  2. http://linux.die.net/man/3/strrchr
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    安全书籍