当前位置:网站首页>C language implementation of strncpy
C language implementation of strncpy
2022-07-28 20:01:00 【Hello_ World_ two hundred and thirteen】
1.strncpy Introduce
strncpy --- String copy --- Copy num Characters
char* strncpy ( char* destination, const char* source, size_t num )
Copy num Characters from the source string to the target space ;
If the source string length is less than num, After copying the source string , Add... After the target ’\0‘, until num individual .
2.strncpy Realization
#include<stdio.h>
#include<assert.h>
#include<stdlib.h>
#include<string.h>
char* my_strncpy(char* destination, const char* source,unsigned int num)
{
assert(destination && source);
char* ret = destination;
while (num&&(*destination++ = *source++))
{
num--;
}
if (num != 0)
{
while (num)
{
*destination++ = '\0';
num--;
}
}
return ret;
}
int main()
{
char arr1[30] = "abcdef";
char arr2[] = "bit";
my_strncpy(arr1, arr2,6);
printf("%s",arr1);
return 0;
}边栏推荐
- A chip company fell in round B
- Article translation software - batch free translation software supports major translation interfaces
- Cell review: single cell methods in human microbiome research
- Special draft of Mir | common sense knowledge and reasoning: representation, acquisition and application (deadline on October 31)
- Source code analysis of scripy spider
- Implementation of markdown editor in editor.md
- Common modules of saltstack
- How does app automated testing achieve H5 testing
- Andorid system layout, values, drawable adaptation
- CodeIgnier框架实现restful API接口编程
猜你喜欢

Information management system and games based on C language

adb remount of the / superblock failed: Permission denied

Getting started with enterprise distributed crawler framework

English Translation Spanish - batch English Translation Spanish tools free of charge

远光软件获得阿里云产品生态集成认证,携手阿里云共建新合作

Basic knowledge of communication network 01

Article translation software - batch free translation software supports major translation interfaces

Intermediate soft test (system integration project management engineer) high frequency test site

English translation Arabic - batch English translation Arabic tools free of charge

Saltstack advanced
随机推荐
The results of the second quarter online moving people selection of "China Internet · moving 2022" were announced
BeanFactory not initialized or already closed - call ‘refresh‘ before accessing beans via the Applic
How openocd directly downloads programs to STM32 board through stlink (solved)
Application skills of programming rising and falling edge instructions of botu 1200/1500plc (bool array)
In order to develop high-end photoresist, Jingrui Co., Ltd. invested 75million yuan to purchase SK Hynix ASML lithography machine
KPMG China: insights into information technology audit projects of securities fund management institutions
Crawl IP
Question bank and answers of the latest national fire-fighting facility operators (intermediate fire-fighting facility operators) in 2022
adb remount of the / superblock failed: Permission denied
C language operators and input and output
MySQL8 基于clone创建主从复制
CDGA|工业互联网行业怎么做好数据治理?
利用STM32的HAL库驱动1.54寸 TFT屏(240*240 ST7789V)
Overcome the "fear of looking at teeth", and we use technology to change the industry
爬取IP
How does app automated testing achieve H5 testing
中国能否在元宇宙的未来发展中取得突破,占领高地?
Leetcode day4 the highest paid employee in the Department
远光软件获得阿里云产品生态集成认证,携手阿里云共建新合作
2022年全国最新消防设施操作员(中级消防设施操作员)题库及答案