c语言中strtok函数_在C语言中使用strtok()和strtok_r()函数

c语言中strtok函数

In this article, we’ll take a look at using the strtok() and strtok_r() functions in C.

在本文中,我们将介绍如何在C语言中使用strtok()和strtok_r()函数。

These functions are very useful, if you want to tokenize a string. C provides these handy utility functions to split our input string into tokens.

如果要标记字符串,这些功能非常有用。 C提供了这些方便的实用程序函数,可将我们的输入字符串拆分为标记。

Let’s take a look at using these functions, using suitable examples.

让我们使用合适的示例来看看如何使用这些功能。



使用strtok()函数 (Using the strtok() function)

First, let’s look at the strtok() function.

首先,让我们看一下strtok()函数。

This function is a part of the <string.h> header file, so you must include it in your program.

此函数是<string.h>头文件的一部分,因此必须在程序中包含它。


#include <string.h>

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

This takes in an input string str and a delimiter character delim.

这将接受输入字符串str和定界符delim

strtok() will split the string into tokens based on the delimited character.

strtok()将根据定界字符将字符串拆分为标记。

We expect a list of strings from strtok(). But the function returns us a single string! Why is this?

我们期望从strtok()获得字符串列表。 但是该函数返回一个字符串! 为什么是这样?

The reason is how the

  • 4
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值