strcmp函数和strcpy函数
来源:互联网 发布:软件项目的社会效益 编辑:程序博客网 时间:2024/05/21 10:38
strcmp stpcpy
原型:extern int strcmp(char *s1,char * s2); 用法:#include <string.h> 功能:比较字符串s1和s2。 说明: 当s1<s2时,返回值<0 当s1=s2时,返回值=0 当s1>s2时,返回值>0 实际上,字符串的比较是比较字符串中各对字符的ASCII码。
首先比较两个串的第一个字符,若不相等,则停止比较并得出大于或小于的结果;
如果相等就接着 比较第二个字符然后第三个字符等等。如果两上字符串前面的字符一直相等,像"abcd"和"abcde" 那样,
前四个字符都一样, 然后比较第 五个字符, 前一个字符串"abcd"只剩下结束符'/0',
后一个字符串"abcde"剩下'e','/0'的ASCII码小于'e'的ASCII 码,所以得出了结果。
因此无论两个字符串是什么样,strcmp函数最多比较到其中一个字符串遇到结束符'/0'为止,就能得出结果。 举例: // strcmp.c #include <stdlib.h>#include <stdio.h> #include <string.h> int main() { char *s1="Hello, World!"; char *s2="Hello, BeiJing!"; int r; r=strcmp(s1,s2); if(!r) printf("s1 and s2 are identical"); else if(r<0) printf("s1 less than s2"); else printf("s1 greater than s2"); return EXIT_SUCCESS; }
原型:extern char *stpcpy(char *dest,char *src); 用法:#include <string.h> 功能:把src所指由NULL结束的字符串复制到dest所指的数组中。 说明:src和dest所指内存区域不可以重叠且dest必须有足够的空间来容纳src的字符串。 返回指向dest结尾处字符(NULL)的指针。 举例: // stpcpy.c #include <stdlib.h> #include <stdio.h> #include <string.h> int main() { char *s="Hello, World!"; char a[20]; strcpy(a,s); printf("%s",a);return EXIT_SUCCESS; }
- strcmp函数和strcpy函数
- strcmp函数和strcpy函数
- strcmp函数和strcpy函数
- strcmp函数和strcpy函数
- strcmp 函数和 strcpy 函数
- strcmp函数和strcpy函数
- strcmp函数和strcpy函数
- strcmp函数和strcpy函数
- strcmp函数和strcpy函数
- strcmp函数和strcpy函数
- strcmp函数和strcpy函数
- strcpy、strlen、strcmp函数
- 函数strcpy、strcat和strcmp实现源码
- 函数strcpy、strcat和strcmp实现源码
- strcpy、strcmp和memcpy 函数实现
- C语言实现strcmp()和strcpy()函数
- strcmp函数与strcpy函数
- strcat , strcpy , strcmp 函数实现
- nginx 的proxy_pass 基本设置问题
- JS中的event 对象详解
- [DNS] 域名格式以及限制
- Java连接数据库(2)
- Atmage32启动参数设置
- strcmp函数和strcpy函数
- ie中关于document.body.scrollLeft总是0的原因
- activity的生命周期
- 大数据过滤及判断算法 -- Bitmap / Bloomfilter
- 使用电脑键盘操作android模拟器
- rails里的filter
- 若爱 就如桃花般地去爱
- usaco 5.2 Wisconsin Squares(DFS)
- Linux 进程管理剖析