当前位置:网站首页>Use of strtok and strError
Use of strtok and strError
2022-07-28 20:01:00 【Hello_ World_ two hundred and thirteen】
One .strtok
char* strtok ( char* str, const char* sep );
sep --- sep The parameter is a string , Defines the set of characters used as separators
char arr[] = " [email protected] " ; // 2913679329 qq com
char* p = " @. " ;
strtok function : From the address of the first character Look backwards one by one arr The separator in (@ and .) Change it to ‘\0’ And then print ; Then from the next character address of the separator Look backwards one by one arr The second separator in Change it to ‘\0’ And then print ; Execute sequentially , until The next character address of the separator Look backwards one by one find arr Medium ‘\0’ stop .
Only one section can be cut at a time , The starting address of the first incoming string , Pass in null pointer for the second time
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<assert.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char arr[] = "[email protected]";
const char* p = "@.";
char buf[1024] = { 0 };
strcpy(buf, arr);
char* ret = NULL;
for (ret = strtok(arr, p); ret != NULL; ret = strtok(NULL, p))
{
printf("%s\n", ret);
}
return 0;
}Be careful :
1.strtok Function changes the string being manipulated , Therefore, when used, the segmented string is generally a temporary copy of the content and can be modified
2.strtok The first argument of the function is not NULL, Function will find str The first mark in ,strtok The function will save its position in the string
3.strtok The first argument to the function is NULL, The function will start at the same position in the string that is saved ( Start at position after marking ), Find next tag
4. If there are no more tags in the string , Then return to NULL.
Two .strerror
strerror --- Return error code , The corresponding error message
char* strerror ( int errnum );
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
int main()
{
//error Is a global error code variable
// When C Language library functions in the process of execution , Something went wrong , The corresponding error code , Assign values to the errno in
FILE* pf = fopen("test.txt", "r");
if (pf == NULL)
{
printf("%s\n", strerror(errno));
}
else
{
printf("open file success\n");
}
return 0;
}边栏推荐
- Common APIs in string
- How many types of rain do you know?
- MySQL8 基于clone创建主从复制
- 架构基本概念和架构本质
- Thoroughly understand bit operations -- and (&), not (~), or (|), XOR (^)
- CodeIgnier框架实现restful API接口编程
- Basic concept and essence of Architecture
- Amazon launched Amazon one palm payment system, and the contactless palm vein recognition market is expected to explode
- 你知道雨的类型有几种?
- MySQL8 Status Variables: Internal Temporary Tables and Files
猜你喜欢

Business visualization - let your flowchart "run" (4. Actual business scenario test)

Cloud computing notes part.1 - system management

数字图像理论知识(一)(个人浅析)

Netcoreapi operation excel table

How to write the SQL statement of time to date?

adb remount of the / superblock failed: Permission denied

shared_ PTR and make_ Use of shared

How does app automated testing achieve H5 testing

软考中级(系统集成项目管理工程师)高频考点

MATLAB实现的图像分割之边缘检测和连接
随机推荐
MySQL command statement (personal summary)
Deploy LNMP automatically with saltstack
一文读懂如何部署具有外部数据库的高可用 K3s
MySQL8 Status Variables: Internal Temporary Tables and Files
Use Hal Library of STM32 to drive 1.54 inch TFT screen (240*240 st7789v)
Leetcode Day2 consecutive numbers
利用STM32的HAL库驱动1.54寸 TFT屏(240*240 ST7789V)
“中国网事·感动2022”二季度网络感动人物评选结果揭晓
C language pointer and two-dimensional array
[network] communication across regional networks learn how routing tables work
In the second half of 2022, the system integration project management engineer certification starts on August 20
Function fitting based on MATLAB
CDGA|工业互联网行业怎么做好数据治理?
Verification of chip power consumption performance: from dilemma to transcendence
Left alignment function of Lua language (handwriting)
Cell review: single cell methods in human microbiome research
KubeEdge发布云原生边缘计算威胁模型及安全防护技术白皮书
11. Learn MySQL union operator
editor.md中markdown编辑器的实现
基于QTGUI图像界面的空战游戏设计