首页 > 系统服务 > 详细

linux 内核中strstr 功能

时间:2015-05-05 16:28:14      阅读:275      评论:0      收藏:0      [点我收藏+]

在内核代码中看到strstr函数:

mode = strstr(boot_command_line, "D:");

应该是一个字符串处理函数,使用man命令查看下给出如下解释:

SYNOPSIS
       #include <string.h>


       char *strstr(const char *haystack, const char *needle);


       #define _GNU_SOURCE


       #include <string.h>


       char *strcasestr(const char *haystack, const char *needle);
DESCRIPTION
       The strstr() function finds the first occurrence of the substring needle in
       the string haystack.  The terminating '\0' characters are not compared.

       The strcasestr() function is like strstr(), but ignores the  case  of  both
       arguments.

RETURN VALUE
       These functions return a pointer to the beginning of the substring, or NULL
       if the substring is not found.


找出字符串needle在haystack中第一次出现的位置,成功返回位子指针,没有找到返回NULL。
简单的例子:

#include <string.h>
#include <stdio.h>

int main()
{
    char *haystack = "Hello, this is csdn blog, I am here";
    char *needle = "he";
    char *temp;

    temp = strstr(haystack, needle);
    if(temp != NULL)
    {
        printf("%s\n", temp);
    }
    else
    {
        printf("can not find [%s] from [%s]\n", needle, haystack);
    }

    return 0;
}


$ gcc strstr.c -o strstr
$ ./strstr

linux 内核中strstr 功能

原文:http://blog.csdn.net/hanglinux/article/details/45503615

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!