当前位置:网站首页>strncat() strncmp()
strncat() strncmp()
2022-07-23 23:12:00 【InfoQ】
strncat() - 连接字符串(受长度限制)
char *strncat(char *dest, const char *src, size_t n)strncat()函数代码示例
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
int main(void)
{
char str1[20];
char str2[20];
strcpy(str1, "Cyuyan");
strcpy(str2, "yyds");
printf(strncat(str1, str2, 5));//追加字符串!
return 0;
}
printf(strncat(str1, str2, 4));

strncat()源程序实现
char * __cdecl strncat (
char * front,
const char * back,
size_t count
)
{
char *start = front;
while (*front++)
;
front--;
while (count--)
if (!(*front++ = *back++))
return(start);
*front = '\0';
return(start);
}
strncmp() - 比较字符串(受长度限制)
int strncmp(const char *str1, const char *str2, size_t nstrncmp()函数代码示例
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
int main(void)
{
char str1[20];
char str2[20];
strcpy(str1, "Cyuyan");
strcpy(str2, "Cyuyanyyds");
printf("%d", strncmp(str1, str2, 6));
return 0;
}strncat()源程序实现
int __cdecl strncmp
(
const char *first,
const char *last,
size_t count
)
{
size_t x = 0;
if (!count)
{
return 0;
}
/*
* This explicit guard needed to deal correctly with boundary
* cases: strings shorter than 4 bytes and strings longer than
* UINT_MAX-4 bytes .
*/
if( count >= 4 )
{
/* unroll by four */
for (; x < count-4; x+=4)
{
first+=4;
last +=4;
if (*(first-4) == 0 || *(first-4) != *(last-4))
{
return(*(unsigned char *)(first-4) - *(unsigned char *)(last-4));
}
if (*(first-3) == 0 || *(first-3) != *(last-3))
{
return(*(unsigned char *)(first-3) - *(unsigned char *)(last-3));
}
if (*(first-2) == 0 || *(first-2) != *(last-2))
{
return(*(unsigned char *)(first-2) - *(unsigned char *)(last-2));
}
if (*(first-1) == 0 || *(first-1) != *(last-1))
{
return(*(unsigned char *)(first-1) - *(unsigned char *)(last-1));
}
}
}
/* residual loop */
for (; x < count; x++)
{
if (*first == 0 || *first != *last)
{
return(*(unsigned char *)first - *(unsigned char *)last);
}
first+=1;
last+=1;
}
return 0;
}
边栏推荐
- Relevant interfaces of [asp.net core] option mode
- 1000个Okaleido Tiger首发上线Binance NFT,引发抢购热潮
- Sword finger offer II 115. reconstruction sequence
- Array - 11. Containers with the most water
- Data sorting and usage before torchvision.datasets.imagefolder
- Is it safe to open a VIP stock account on your mobile phone?
- Array -- 209. Subarray with the smallest length
- Lixia action 2022 Yuanqi digital round table forum will be launched soon
- 使用itextpdf提取PDF文件中的任意页码
- Array - 704. Binary search
猜你喜欢

Series of articles | the way to advance the microservice architecture in the cloud native era - best practices of microservice splitting

(CVPR-2022)BiCnet

FL Studio 20.9 update Chinese version host Daw digital audio workstation

Analysis of video capability and future development trend based on NVR Technology

Profit logic of DFI project 2021-04-26

TAP 系列文章9 | 应用开发加速器

Microsoft SQL Server database language and function usage (XIII)

The role of physical layer, link layer, network layer, transport layer and application layer of tcp/ip model of internet protocol stack

torchvision.datasets.ImageFolder前的数据整理及使用方法

作为开发,你不得不知道的三个性能测试工具|Jmeter、Apipost、JMH使用指南
随机推荐
Array - 59. Spiral matrix II
QT set cache and compile output path
系列文章|云原生时代下微服务架构进阶之路 - 微服务拆分的最佳实践
Series of articles | the way to advance the microservice architecture in the cloud native era - best practices of microservice splitting
Investment suggestions for overseas senior players (3) 2021-05-04
mysqlbinlog命令介绍(远程拉取binlog日志)
作为开发,你不得不知道的三个性能测试工具|Jmeter、Apipost、JMH使用指南
糖尿病遗传风险检测挑战赛Baseline
Linked list - 203. remove linked list elements
【Matplotlib绘图】
ES6箭头函数的使用
About: enable delivery optimization in enterprise LAN
Internet协议栈 TCP/IP模型 物理层、链路层、网络层、传输层、应用层的作用
$, $*, [email protected], $$ Understand the meaning of 0
EasyNVR平台如何关闭匿名登录?
接口测试
Programming in the novel [serial 19] the moon bends in the yuan universe
dried food! Implicit sparse regularization effect in neural networks
视频号加强打击低俗内容:对违背公序良俗的内容必须赶尽杀绝
TAP 系列文章7 | 易于管理的流水线配置