C语言 stringcpy,stringcat,stringcmp实现
来源:互联网 发布:数据共享交换平台 编辑:程序博客网 时间:2024/06/05 19:52
C语言 stringcpy,stringcat,stringcmp实现 - kingshow - 博客园
http://www.cnblogs.com/kingshow123/p/stringoperation.html
#include<stdio.h>#include<conio.h>//实现从源字符串string到目的字符串str的复制函数char* stringCpy(char* str,const char* string){ char* s=str; while(*string) { *s++=*string++; } *s='\0'; //返回目的字符串的首地址 return str;}//函数将字符串string链接到字符串str的尾部char* stringCat(char* str,const char* string){ char* s=str; //找到字符串str的尾部 while(*s) { s++; } while(*string) { *s++=*string++; } *s='\0'; //返回目的字符串的首地址 return str;}//比较大小的函数//实现两个字符串str和string的比较//如果str小于string返回负值,如果str大于string返回正直,如果str等于string返回0int stringCmp(const char* str,const char* string){ while((*str)&&(*string)&&(*str==*string)) { str++; string++; } return (int)(*str-*string);}int main(){ char s1[20]; const char* s2="abc"; const char* s3="def"; char* pc; int cmp; puts("**************************************"); puts("| The program will complish: |"); puts("| strcpy,strcat,strcmp |"); puts("**************************************"); printf("The string s2 is:%s\n",s2); printf("The string s3 is:%s\n",s3); pc=stringCpy(s1,s2); printf("This is stringcpy s2 to s1,s1 is :\n"); puts(pc); pc=stringCat(s1,s3); printf("This is stringcat s1 to s3,s1 is :\n"); puts(pc); cmp=stringCmp(s2,s3); if(cmp==0) printf("\nThe string s2 is equal to s3\n"); else if(cmp<0) printf("\nThe string s2 is smaller to s3\n"); else printf("\nThe string s2 is larger to s3\n"); getch();//从控制台读取一个字符,但不显示在屏幕上,实现在该位置暂停一下,按任意键继续 return 0;}
0 0
- C语言 stringcpy,stringcat,stringcmp实现
- stringcat再会
- 问题九:编写函数stringcat,实现字符串的连接,程序中需要使用指针形式访问字符串
- 问题一:编写函数stringcat,实现字符串的连接,程序中需要使用指针形式访问字符串
- 链栈 C语言实现
- 地球 c语言实现
- C语言实现堆栈
- c语言实现计算器
- TrimLeft C语言实现
- C语言实现有限状态机
- 迪杰斯特拉 C语言实现
- C语言实现FIR
- C语言实现有限状态机
- C语言实现双链表
- C语言实现析构器
- C语言实现:万年历
- C语言实现有限状态机
- 二叉排序树 C语言实现
- Delphi 通过IConnectionPointContainer响应COM事件的例子,Internet Explorer 事件响应
- 程序运行过程中的各个寄存器!
- Eclipse 中 显示代码的行号
- 最新的Android SDK安装攻略(动作要快,来晚就失效了)
- 武道释义 · 零散
- C语言 stringcpy,stringcat,stringcmp实现
- Makefile
- 成佩涛-项目管理成功之六大因素
- python 下载整个网站
- 判断两条线段是否相交_模版
- 2014百度笔试算法题
- Brocade MAPS Overview
- Android 自动化测试(2)根据ID查找对象(java)
- scala中reduceLeft的应用