#include <stdio.h>
#include <stdlib.h> int strlen(const char *str)
{
int length=;
while(*str++!='\0')
{
length++;
}
return length;
} char *strcopy(char *dest,const char *source)
{
if(source==NULL)
{
printf("Error:StrSource is NULL \n");
}
dest=(char *)malloc(strlen(source)+);//多一个空间用来存储字符串结束符'\0' char *p=dest;
while(source!='\0')//这里应该改为while(*source!='\0')....
{
*p++=*source++;
}
*p='\0';
return dest;
} int main()
{
const char *src="fuckoff jerk!!";
char *des=NULL;
des=strcopy(des,src);
if(des!=NULL){
free(des);
des=NULL;
}
return ;
}

以上代码.编译通过. 运行时出现段错误.
请大家帮我看看问题出在哪里..

关于strcpy的实现.的更多相关文章

  1. strcpy函数在VS2015无法使用的问题

    一:原因:一般认为是vs准备弃用strcpy的,安全性较低,所以微软提供了strcpy_s来代替 然而,strcpy_s并没有strcpy好用,我们要想继续在VS2015中使用strcpy该怎么办 呢 ...

  2. 你必须知道的指针基础-4.sizeof计算数组长度与strcpy的安全性问题

    一.使用sizeof计算数组长度 1.1 sizeof的基本使用 如果在作用域内,变量以数组形式声明,则可以使用sizeof求数组大小,下面一段代码展示了如何使用sizeof: ,,,,,}; int ...

  3. strcpy 函数的实现

    原型声明:extern char *strcpy(char *dest,const char *src); 头文件:string.h   功能:把从src地址开始且含有‘\0’结束符的字符串赋值到以d ...

  4. Linux C 字符串函数 strlen()、strcat()、strncat()、strcmp()、strncmp()、strcpy()、strncpy() 详解

      strlen(返回字符串长度) 表头文件 #include <string.h> 定义函数 size_t strlen(const char *s); 函数说明 strlen()用来计 ...

  5. strncpy,strcpy

    strncpy不会为des自动添加“\0” strcpy遇空结束,自动添加结束符 结论: 1.使用strcpy时一定不能用于无结束符的字符串,因为strcpy依赖\0判断源字符串的结束 2.使用str ...

  6. strcpy strlen memcpy等的函数实现

    #include <assert.h> #include <string.h> #include <stdlib.h> #include <stdio.h&g ...

  7. 字符串strcpy

    strcpy函数的表达方式: //把一个char组成的字符串循环右移n个,如:“abcdefghi",n=2,移动后"hiabcdefgh" #include <i ...

  8. strlen(); strcpy(); strcat(); strcmp() ---笔记

    指针小知识点: int a =10; int *p=&a; int *q=p;        //p中保存的是a的地址 int *q=p;       //将p的值赋给q 作用是让q也指向a ...

  9. strcpy 库函数 拷贝函数

    strcpy 是在string.h 里面 #include "stdafx.h"#include "string.h"struct Student{int Se ...

  10. strcpy和memcpy的区别(转载)

    strcpy和memcpy都是标准C库函数,它们有下面的特点.strcpy提供了字符串的复制.即strcpy只用于字符串复制,并且它不仅复制字符串内容之外,还会复制字符串的结束符. 已知strcpy函 ...

随机推荐

  1. ssh框架用JUnit测试

    public class testAuxDict { //读spring配置文件 public static BeanFactory factory = new ClassPathXmlApplica ...

  2. EBS-利用form个性化 调用报表【Z】

    1.在工具中添加调用报表的功能 条件: 触发器事件:WHEN-NEW-FORM-INSTANCE 活动: 类型为:菜单 菜单项:specialn n为1..6 菜单标签:打印xx报表 2.对speci ...

  3. ucenter 同步登录总结

    部署: discuz默认安装后就安装了uc_server应用 各应用根目录必须有uc_client文件夹. 下载ucenter程序查看范例程序 应用管理中,应用的主 URL必须指向到应用的根目录,应用 ...

  4. 无缝滚动 jQuery经典代码 (收藏)

    <script language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4 ...

  5. python 连接数据库-设置oracle ,mysql 中文字符问题

    import cx_Oracle import MySQLdb def conn_oracle(): cnn = cx_Oracle.connect('用户名','密码','ip:端口号/数据库') ...

  6. 编写一个程序实现strcat函数的功能

    写自己的strcat函数------→mycat #include <stdio.h> #include <string.h> #define N 5 char *mycat( ...

  7. log实例

    配置详解见2014.10月篇 log4j的pom.xml <dependency> <groupId>log4j</groupId> <artifactId& ...

  8. 18.java.lang.OutOfMemoryException

    java.lang.OutOfMemoryException内存不足错误 当可用内存不足以让Java虚拟机分配给一个对象时抛出该错误.

  9. iOS6和iOS7代码的适配(2)——status bar

    用Xcode5运行一下应用,第一个看到的就是status bar的变化.在iOS6中,status bar是系统在处理,应用中不需要考虑这部分,iOS7之后是应用在处理,每个ViewControlle ...

  10. thunk的主要用法

    主要用法目前用的多的就三种; thunk.all 并发 thunk.sql 同步 thunk.race 最先返回的进入结果输出 前两个返回的结果都是数组,最后一个返回的是对象: thunk的链式调用没 ...