第16周项目2-用指针玩字符串(7)字符串比较
来源:互联网 发布:知画生孩子第29集 编辑:程序博客网 时间:2024/06/11 08:28
/**Copyright (c) 2014,烟台大学计算机学院*All rights reserved.*文件名称:Annpion.cpp*作者:王耀鹏*完成日期:2014年12月17日*版本号:v1.0**问题描述:用指针玩字符串。*输入描述:不输入。*程序输出:字符串比较。*/#include <iostream>#include <iomanip>using namespace std;int pstrcmp(char *str1, char *str2);int main(void){ char *s[81]= {"Tudou","Shanyaodan","Yangyu","Malingshu"}; int i=0,j=0; cout<<"土豆大PK:"<<endl; cout<<setw(12)<<" "; for(; i<4; i++) { cout<<setw(12)<<s[i]; } cout<<endl; for(i=0; i<4; i++) { cout<<setw(12)<<s[i]; for(j=0; j<4; j++) { cout<<setw(12)<<pstrcmp(s[i],s[j]); } cout<<endl; } return 0;}int pstrcmp(char *str1, char *str2){ int i=0; while(*(str1+i)==*(str2+i)&&*(str1+i)!='\0'&&*(str2+i)!='\0') i++; if(*(str1+i)>*(str2+i)) return 1; else if(*(str1+i)<*(str2+i)) return -1; else return 0;}
运行结果:
0 0
- 第16周项目2-用指针玩字符串(7)字符串比较
- 第16周项目2--用指针玩字符串(字符串的比较)
- 第16周项目2-用指针玩字符串(任务七:比较字符串)
- 第16周项目2(7)-用指针玩字符串
- C++第17周项目2——用指针玩字符串(7)比较
- 第16周项目2 用指针玩字符串2
- 第16周项目2(4)-用指针玩字符串
- 第16周项目2(5)-用指针玩字符串
- 第16周项目2(6)-用指针玩字符串
- 第16周项目2-用指针玩字符串
- 第16周【项目 2-用指针玩字符串】①
- 第16周【项目 2-用指针玩字符串】②
- 第16周 项目2-用指针玩字符串(1)
- 第16周【项目 2-用指针玩字符串】③
- 第16周【项目 2-用指针玩字符串】④
- 第16周【项目 2-用指针玩字符串】⑤
- 第16周【项目 2-用指针玩字符串】⑥
- 第16周【项目 2-用指针玩字符串】⑦
- 快速排序
- iOS: 使用CGContextRef,CGPath和UIBezierPath来绘画
- Java中的成员变量和局部变量
- 你应该知道的令APP获得百万下载的14个方法
- 使用VisualSVN Server搭建SVN服务器 (Windows环境为例)
- 第16周项目2-用指针玩字符串(7)字符串比较
- SPDY:一种更快速web的实验协议
- Flashback
- 图论500题,默默奋斗
- SqlServer 如何将查询出的多行数据拼成一个字符串返回
- linux下定期备份mysql数据库
- C#中改变ListView中ColumnHeader的颜色
- iOS: 关于CALayer的contentsCenter属性
- Linux中的通配符