用c语言编程实现strcpy,用c语言.模拟实现strcpy,strcat,strcat,memcpy,memmove
1.模拟实现strcpy
#include
#include
#include
#include
char *my_strcpy(char *dst, const char *src)
{
assert(dst != null);
assert(src != null);
char *ret = dst;
while ((*dst++ = *src++) != '\0')
;
return ret;
}
int main()
{
char arr1[] = "hello world!!!";
char arr2[20];
my_strcpy(arr2, arr1);
printf("%s\n", arr2);
system("pause");
return 0;
}
2.模拟实现strcat
#include
#include
#include
char *strcat(char *dest, char const *src)
{
assert(dest);
assert(src);
char *temp = dest;
while (*dest)
{
dest++;
}
while (*src)
{
*dest++ = *src++;
}
*dest = '\0';
return temp;
}
int main()
{
char arr[50] = "i come from china!!";
char *p = " me too!!";
strcat(arr, p);
printf("%s", arr);
system("pause");
return 0;
}
3.模拟实现strcat
#include
#include
#include
int my_strcmp(const char *arr1, const char *arr2)
{
assert(arr1);
assert(arr2);
while (*arr1 == *arr2)
{
if (*arr1 == '\0')
{
return 1;
}
arr1++;
arr2++;
}
return *arr1 - *arr2;
}
int main()
{
char *s1 = "i am a student!";
char *s2 = "i am a student!";
int ret=my_strcmp(s1, s2);
if (ret == 1)
{
printf("两个字符串相同!\n");
}
else{
printf("两个字符串差值为:%d\n", ret);
}
system("pause");
return 0;
}
4.模拟实现memcpy
#include
#include
#include
#include
void *my_memcpy(void *dest, const void *src, size_t n)
{
assert(dest);
assert(src);
char *p = (char *)dest;
const char *q = (char *)src;
while (n--)
{
*p = *q;
p++;
q++;
}
return dest;
}
int main()
{
int arr1[100] = { 1,2,3,4,5,6,7,8,9,10,11 };
int arr2[100] = { 0 };
int i = 0;
int num;
printf("请输入要拷贝的个数:");
scanf("%d", &num);
my_memcpy(arr2, arr1, 4*num);
for (i = 0; i < num; i++)
{
printf("%d ", arr2[i]);
}
printf("\n");
system("pause");
return 0;
}
5.模拟实现memmove
#include
#include
#include
#include
void *my_memcpy(void *dest, const void *src, size_t n)
{
assert(dest);
assert(src);
char *p = (char *)dest;
const char *q = (char *)src;
if (p > q && p < q + n)
{
while (n--)
{
*(p + n) = *(q + n);
}
}
else
{
while (n--)
{
*p = *q;
p++;
q++;
}
}
return dest;
}
int main( )
{
int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int i = 0;
my_memcpy(arr+4, arr+2, 20);
for (i = 0; i < 10; i++)
{
printf("%d ", arr[i]);
}
printf("\n");
system("pause");
return 0;
}
用c语言编程实现strcpy,用c语言.模拟实现strcpy,strcat,strcat,memcpy,memmove相关推荐
- 高斯消元法的c语言编程,列主元高斯消元法的C语言编程
列主元高斯消元法的C语言编程 列主元高斯消元法 基本思想:用高斯消元法求解线性方程组时,为避免小的主元,在进行第k步消元前,应该在第k列(k)元素aik(i k,(k)(k)例如|aikk| max| ...
- c语言程序设计自学跟谁好,双辽c语言编程学习,双辽学c语言编程哪个好,双辽学c语言编程自学好还是报班好...
双辽c语言编程学习,双辽学c语言编程哪个好,双辽学c语言编程自学好还是报班好 首页 > 软件 > 双辽c语言编程学习 作者:镀金池 发布时间:2017-12-07 05:48 一个C语 ...
- c语言程序设计需要学多久,九江c语言编程学习,九江学c语言编程报班,九江学c语言编程一般要多久才能学会...
九江c语言编程学习,九江学c语言编程报班,九江学c语言编程一般要多久才能学会 首页 > C语言 > 九江c语言编程学习 作者:镀金池 发布时间:2017-10-18 14:11 据ID ...
- c语言编程期刊论文管理系统,C语言编程下计算机软件论文
1计算机软件C语言的编程实验 1.1计算机软件C语言的编程技巧 计算机软件C语言的编程中,最主要的依据是指针应用,C语言指针能够根据软件程序的编写需求,构建可行的函数,而程序员在设计函数编程的过程中, ...
- c语言编程学多久,丰城c语言编程学习,丰城学c语言编程的学校,丰城学c语言编程一般要多久才能学会...
丰城c语言编程学习,丰城学c语言编程的学校,丰城学c语言编程一般要多久才能学会 首页 > 软件 > 丰城c语言编程学习 作者:镀金池 发布时间:2018-04-09 16:40 在之后 ...
- 江门C语言培训,江门c语言编程学习,江门学c语言编程培训,江门学c语言编程效果怎么样...
江门c语言编程学习,江门学c语言编程培训,江门学c语言编程效果怎么样 首页 > C语言 > 江门c语言编程学习 作者:镀金池 发布时间:2017-10-18 09:25 在初期的C语言 ...
- C语言报名里面培训怎么填,庄河c语言编程学习,庄河学c语言编程培训,庄河学c语言编程报个培训班怎么样...
庄河c语言编程学习,庄河学c语言编程培训,庄河学c语言编程报个培训班怎么样 首页 > 软件 > 庄河c语言编程学习 作者:镀金池 发布时间:2017-11-29 11:13 明天利用时 ...
- 罗定c语言,罗定学c语言编程,罗定学c语言编程培训,罗定学c语言编程一般怎么收费...
罗定学c语言编程,罗定学c语言编程培训,罗定学c语言编程一般怎么收费 首页 > 软件 > 罗定学c语言编程 作者:镀金池 发布时间:2018-10-04 23:40 依照c语言的法则, ...
- 安庆师范大学c语言程序设计,安庆c语言编程学习,安庆学c语言编程培训,安庆学c语言编程一般能拿多少工资...
安庆c语言编程学习,安庆学c语言编程培训,安庆学c语言编程一般能拿多少工资 首页 > C语言 > 安庆c语言编程学习 作者:镀金池 发布时间:2017-10-18 15:20 假定我们 ...
- 汕头c语言培训班,汕头c语言编程学习,汕头学c语言编程哪个好,汕头学c语言编程需要报培训班吗...
汕头c语言编程学习,汕头学c语言编程哪个好,汕头学c语言编程需要报培训班吗 首页 > C语言 > 汕头c语言编程学习 作者:镀金池 发布时间:2017-10-18 20:12 经历:若 ...
最新文章
- R语言临床预测模型的评价指标与验证指标实战:C-index指标计算
- 《DB2性能管理与实战》导读
- 一个字符串排列的小算法
- 【Flink】ERROR - Exception occurred in REST handler: Job xxx not found
- Spring : 缓存相关注解@EnableCaching、@CacheConfig、@Cacheable、@Caching
- flask-alchemy-pagination
- SQL Server跨server之间訪问
- php for of,JavaScript中 for、for in、for of、forEach的用法小结(附代码)
- shell编程(精华总结版)
- 跟着杨中科学习asp.net之javascript
- MAC 重置 MySql密码步骤
- CISCO 命令手册
- 详细解说iexplore.exe
- 轩辕剑--资料集(三)
- Dremel学习总结2
- linux不启动修改rcs文件,linux根文件系统制作之rcS文件分析
- 【Python 八股文 】- Python基础
- 大数据在互联网经济发展中的应用
- 使用Python将sin(x)和cos(x)画在同一个图例里
- 投票点赞链接制作投票链接在线制作投票图文链接制作点赞
热门文章
- 错误:java.lang.ClassNotFoundException:org.apache.commons.fileupload.FileItemFactory 解决方案...
- django模板中使用JQ代码实现瀑布流显示效果
- docker 部署mysql服务之后,执行sql脚本
- MySQL基础学习过程
- WordPress网站的问题
- javascript的时间段选择
- Java 8特性有望进入.Net/Mono
- Hibernate关联关系映射-----双向一对多/多对一映射配置
- [转] GIS算法源码集合
- js 正则判断字符串是否为字母或数字