C语言标准库函数strcpy与strcmp的简单实现
//C语言标准库函数strcpy的一种简单实现。 //返回值:目标串的地址。 //对于出现异常的情况ANSI-C99标准并未定义,故由实现者决定返回值,通常为NULL。 //参数:des为目标字符串,source为原字符串。 char* strcpy(char* des,const char* source)
{
char* r=des; assert((des != NULL) && (source != NULL)); while((*des++ = *source++)!='\0'); return r;
} //while((*des++=*source++));的解释:赋值表达式返回左操作数,所以在赋值NULL后,循环停止。
//C语言标准库函数strcmp的一种简单实现 //返回值当s1<s2时,返回为负数;当s1=s2时,返回值= 0;当s1>s2时,返回正数 //参数:字符串str1,str2 int strcmp(const char *str1,const char *str2)
{
/*不可用while(*str1++==*str2++)来比较,当不相等时仍会执行一次++,
return返回的比较值实际上是下一个字符。应将++放到循环体中进行。*/
while(*str1 == *str2)
{
if(*str1 == '\0')
return 0; str1++;
str2++;
}
return *str1 - *str2;
}
C语言标准库函数strcpy与strcmp的简单实现的更多相关文章
- 转:strcat与strcpy与strcmp与strlen
转自:http://blog.chinaunix.net/uid-24194439-id-90782.html strcat 原型:extern char *strcat(char *dest,cha ...
- 不使用库函数、自己编写的(strlen、strcpy、strcmp、strcat、memcmp、memcpy、memmove)
不使用库函数.自己编写的(strlen.strcpy.strcmp.strcat.memcmp.memcpy.memmove) //求字符串长度的函数 int my_strlen(const char ...
- C语言标准库函数(网络上copy的)
C语言标准库函数 标准io函数Standard C I/Oclearerr() clears errorsfclose() close a filefeof() true if at the end- ...
- 转:C语言字符串操作函数 - strcpy、strcmp、strcat、反转、回文
转自:C语言字符串操作函数 - strcpy.strcmp.strcat.反转.回文 C++常用库函数atoi,itoa,strcpy,strcmp的实现 作者:jcsu C语言字符串操作函数 1. ...
- C语言字符串操作函数 - strcpy、strcmp、strcat、反转、回文
原文:http://www.cnblogs.com/JCSU/articles/1305401.html C语言字符串操作函数 1. 字符串反转 - strRev2. 字符串复制 - strcpy3. ...
- 逆向 string.h 函数库 memset、strcpy、strcmp 函数
memset 函数 函数原型:void *memset(void *str, int c, size_t n) 主要功能:复制字符 c(一个无符号字符)到参数 str 所指向的字符串的前 n 个字符 ...
- 库函数strcpy/strlen的工作方式
库函数strcpy/strlen的工作方式 分类: C/C++ 2011-07-03 23:49 1032人阅读 评论 ...
- c语言中几个常见的库函数strlen、strcmp、strcat、strcpy、strncpy、memset、memcpy、memmove、mmap
1.strlen() 1)计算给定字符串的长度,不包括’\0’在内 unsigned int strlen(const char *s) { assert(NULL != s);//如果条件不满足,则 ...
- 字符串相关函数-strcpy()与strcmp()
一些小问题,避免出现低级错误. 1.strcmp(s1,s2): 字符串指针不见'\0'不回头,这个常在与单个字符作比较时写着写着就忘了. char* p_ch1="this is an e ...
随机推荐
- 转:YUV RGB 常见视频格式解析
转: http://www.cnblogs.com/qinjunni/archive/2012/02/23/2364446.html YUV RGB 常见视频格式解析 I420是YUV格式的一种,而Y ...
- 在IIS上发布项目后浏览时报的错:Unable to make the session state request to the session state server
错误描述: Unable to make the session state request to the session state server. Please ensure that the A ...
- DIV+CSS解决IE6,IE7,IE8,FF兼容问题
1.IE8下兼容问题,这个最好处理,转化成IE7兼容就可以.在头部加如下一段代码,然后只要在IE7下兼容了,IE8下面也就兼容了:1. <metahttp-equivmetahttp-equiv ...
- 在sql设计中没法修改表结构
在做练习的时候经常表没设计好,后来有要去数据库修改表结构但是没词用界面修改的时候都会提示要保存 转自http://www.57xue.com/ItemView/Sql/2016061600160.ht ...
- CSS之上边栏
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- lamp环境的配置
转载请注明原作者出处 write by xiaoyang 一. 先决条件 系统:RHEL Server6.5 工具:MySQL.MySQL Server.PHP.PHP-MySQL.HTTPD等 ...
- 解析Path方法备忘
public static String parseDataPath(String dataPath){ StringBuilder parseBld = new StringBuilder(); L ...
- cass实体编码列表
地物名称 编码 图层 类别 参数一 参数二 实体类型 三角点 131100 KZD 20 gc113 3 SPECIAL,1 三角点分数线 131110 KZD 附 LINE 三角点高程注记 1311 ...
- 一些常用的字符串hash函数
unsigned int RSHash(const std::string& str) { unsigned int b = 378551; unsigned int a = 63689; u ...
- C++ Vector 动态数组
Vectors 包含着一系列连续存储的元素,其行为和数组类似.访问Vector中的任意元素或从末尾添加元素都可以在常量级时间复杂度内完成,而查找特定值的元素所处的位置或是在Vector中插入元素则是线 ...