关于strcpy的实现.
#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的实现.的更多相关文章
- strcpy函数在VS2015无法使用的问题
一:原因:一般认为是vs准备弃用strcpy的,安全性较低,所以微软提供了strcpy_s来代替 然而,strcpy_s并没有strcpy好用,我们要想继续在VS2015中使用strcpy该怎么办 呢 ...
- 你必须知道的指针基础-4.sizeof计算数组长度与strcpy的安全性问题
一.使用sizeof计算数组长度 1.1 sizeof的基本使用 如果在作用域内,变量以数组形式声明,则可以使用sizeof求数组大小,下面一段代码展示了如何使用sizeof: ,,,,,}; int ...
- strcpy 函数的实现
原型声明:extern char *strcpy(char *dest,const char *src); 头文件:string.h 功能:把从src地址开始且含有‘\0’结束符的字符串赋值到以d ...
- Linux C 字符串函数 strlen()、strcat()、strncat()、strcmp()、strncmp()、strcpy()、strncpy() 详解
strlen(返回字符串长度) 表头文件 #include <string.h> 定义函数 size_t strlen(const char *s); 函数说明 strlen()用来计 ...
- strncpy,strcpy
strncpy不会为des自动添加“\0” strcpy遇空结束,自动添加结束符 结论: 1.使用strcpy时一定不能用于无结束符的字符串,因为strcpy依赖\0判断源字符串的结束 2.使用str ...
- strcpy strlen memcpy等的函数实现
#include <assert.h> #include <string.h> #include <stdlib.h> #include <stdio.h&g ...
- 字符串strcpy
strcpy函数的表达方式: //把一个char组成的字符串循环右移n个,如:“abcdefghi",n=2,移动后"hiabcdefgh" #include <i ...
- strlen(); strcpy(); strcat(); strcmp() ---笔记
指针小知识点: int a =10; int *p=&a; int *q=p; //p中保存的是a的地址 int *q=p; //将p的值赋给q 作用是让q也指向a ...
- strcpy 库函数 拷贝函数
strcpy 是在string.h 里面 #include "stdafx.h"#include "string.h"struct Student{int Se ...
- strcpy和memcpy的区别(转载)
strcpy和memcpy都是标准C库函数,它们有下面的特点.strcpy提供了字符串的复制.即strcpy只用于字符串复制,并且它不仅复制字符串内容之外,还会复制字符串的结束符. 已知strcpy函 ...
随机推荐
- 使用PowerDesigner创建数据库表图文并茂版
使用PowerDesigner创建数据库表图文并茂版 使用PowerDesigner 建数据库表. 一直很忙,没有时间写东西.这次搞点会声会色的,嘿嘿 此技能为项目经理必备技能. 本次主角: 1.在w ...
- oracle ORA-00913: 值过多
--oracle中查看表是否被锁 查看表是否被锁 SELECT /*+ rule*/ a.sid, b.owner, object_name, object_type FROM v$loc ...
- 加密传输SSL协议8_Apache服务器的安装
学习了那么多的理论的知识,下面通过在Apache服务器中安装和使用SSL协议,实现安全传输,但是首先要安装好Apache服务器. Apache服务器的安装 Linux下所有的软件的原码的安装都是三部曲 ...
- mysql学习笔记--第1天
1.像网页上的账户.图片.文章都是存在数据库里面2.Oracle .DB2 .SQL server等等多钟数据库 PHP中选择使用mysql PHP+mysql黄金搭档 PHP和mysql都是开源的, ...
- You have not agreed to the Xcode license.
You have not agreed to the Xcode license. Before running the installer again please agree to the lic ...
- 50行实现简易HTTP服务器
话说由于一直很懒,所以博客好像也没怎么更新...今天有空就写一下吧. 最近在看node.js的时候开始对http协议感兴趣了,毕竟node一开始就是为了做web服务器而产生的.于是试着想了一下大概的思 ...
- Delphi判断一个文件是不是JPG图片
判断头几个字节: function IsJpegFile(FileName: string): Boolean; const RightBuf : ..] of Byte = ($FF,$D8,$FF ...
- 截取字符串一之substring
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- UVa 10330 - Power Transmission(最大流--拆点)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- HDU 3037 Saving Beans(Lucas定理的直接应用)
解题思路: 直接求C(n+m , m) % p , 由于n , m ,p都非常大,所以要用Lucas定理来解决大组合数取模的问题. #include <string.h> #include ...