b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

strstr函数的用法_c find函数返回值_strchr函数(7)

电脑杂谈  发布时间:2017-01-31 04:07:50  来源:网络整理

/* 总结:strsep返回为分割后的开始字符串,

并将函数的第一个参数指针指向分割后的剩余字符串。

它适用于分割关键字在两个字符串之间只严出现一次的情况 */

 return 0;
}

7 strtok

通过分隔子字符串,分割目标字符串

int main (void )
{
/* NAME

strtok - extract tokens from strings

* SYNOPSIS

#include <string.h>

char *strtok(char *str, const char *delim);

* DESCRIPTION

The strtok() function parses a string into a sequence of tokens.

On the first call to strtok() the string to be parsed should be specified in str.

In each subsequent call that should parse the same string, str should be NULL.

The delim argument specifies a set of characters that delimit the tokens in the parsed string.

The caller may specify different strings in delim in successive calls that parse the same string.

Each call to strtok() returns a pointer to a null-terminated string containing the next token.

This string does not include the delimiting character. If no more tokens are found, strtok() returns NULL.

A sequence of two or more contiguous delimiter characters in the parsed string is considered to be a single delimiter.

Delimiter characters at the start or end of the string are ignored. Put another way: the tokens returned by strtok() are always non-empty strings.

* RETURN VALUE

The strtok() functions return a pointer to the next token, or NULL if there are no more tokens.

*/

   char pSrc[] = ".baidu.com.education.mahuateng";
    char *pRetval = NULL;

    printf("[%s]-[%d] pSrc = %s\n", __func__, __LINE__, pSrc);
    pRetval = strtok( (char *)pSrc, ".");
/* 个人理解:以"."子字符串为分隔符,分解目标字符串为一组子字符串,并且过滤掉分隔符

如果有子串分隔符的话,则将此处分隔符更改为'\0',目标字符串因此也发生改变,

当再次在以前的字符串中分解字串的话,则需要要把目标字串的参数置NULL,

不存在则返回NULL*/

while( NULL != pRetval )
    {
        printf("[%s]-[%d] pRetval = %s\n", __func__, __LINE__, pRetval);

        pRetval = strtok( NULL, ".");
    }

    printf("[%s]-[%d] pSrc = %s\n", __func__, __LINE__, pSrc);

/* 总结:strtok内部记录上次调用字符串的位置,

所以不支持多线程,可重入版本为strtok_r,有兴趣的可以研究一下。

它适用于分割关键字在字符串之间是“单独”或是 “连续“在一起的情况。 */

  return 0;
}


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-29692-7.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...