zoukankan
html css js c++ java
C++ 编写strcpy函数
小小的一段strcpy函数,却能看出不少的问题。
在此作一下备忘:
#include
<
iostream
>
#include
<
string
>
using
namespace
std;
char
*
str_copy(
char
*
dest,
const
char
*
src);
int
main()
{
char
*
src
=
"
this is a test
"
;
cout
<<
strlen(src)
<<
endl;
//
申请内存大小时,需要在源串的长度上加1,以存放\0
char
*
test
=
(
char
*
)(malloc(strlen(src)
+
1
));
cout
<<
sizeof
(test)
<<
endl;
str_copy(test,src);
if
(test
!=
NULL)
{
cout
<<
test
<<
endl;
}
else
{
cout
<<
"
No Enters
"
<<
endl;
}
free(test);
//
for console test
char
c;
cin
>>
c;
//
end test
return
0
;
}
;
char
*
str_copy(
char
*
dest,
const
char
*
src)
{
if
(dest
==
NULL)
{
return
NULL;}
if
(src
==
NULL
||
*
src
==
'
\0
'
)
{
return
NULL;}
char
*
testTemp
=
dest;
while
((
*
testTemp
++=*
src
++
)
!=
'
\0
'
);
return
testTemp;
}
<h3>
心静似高山流水不动,心清若巫峰雾气不沾。
</h3>
查看全文
相关阅读:
SQL日常维护的语句
87岁老奶奶用微软自带画图软件绘画 惊艳了世人
87岁老奶奶用微软自带画图软件绘画 惊艳了世人
87岁老奶奶用微软自带画图软件绘画 惊艳了世人
.NET开源项目小功能组件
.NET开源项目小功能组件
.NET开源项目小功能组件
常用 SQL Server 规范集锦
常用 SQL Server 规范集锦
常用 SQL Server 规范集锦
原文地址:https://www.cnblogs.com/McJeremy/p/1432190.html
最新文章
Flume 实战练习
JDK_Packages_java_utils
js 将json字符串转换为json对象的方法解析
C语言中不同变量的访问方式
容易出错的JavaScript题目集锦
Linux上centOs6+安装mysql5.7详细教程
[Gem] AASM 狀態機
View 属性
吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-th-list
吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-th
热门文章
吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-th-large
吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-film
吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-user
吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-star-empty
吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-star
吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-heart
吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-search
吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-music
java中try 与catch的使用
Solid-state storage management
Copyright © 2011-2022 走看看