比较字符串大小strcmp
2013-04-29 21:05
344 查看
#include <iostream> #include <assert.h> using namespace std; //比较字符串大小 s - t int strcmp(const char *s, const char *t) { assert(s != NULL && t != NULL); //断言保证传进来的参数不是空 while (*s && *t && *s == *t) //保证两者还有指向内容,并且相等 { ++s; ++t; } return (*s - *t); } int main(void) { char *s = "hello world"; char *t = "hello"; //char a[10] = {0}; cout<<strcmp(s,t);//32 char r = ' '; cout<<int(r);//空格的值是32 system("pause"); return 0; }
相关文章推荐
- c++实现字符串strcmp()大小比较
- strcmp()比较字符串大小原理
- 比较字符串的大小(strcmp、strcpy)
- 不使用strcmp函数比较两个字符串的大小
- 比较2个字符串的大小strcmp
- 从键盘输入两个字符串,不用字符串函数strcmp()比较两者的大小
- java数字字符串比较大小
- shell中怎么比较两个字符串的大小?
- 关于不等长字符串的大小比较
- Java:日期字符串格式大小比较
- sql server中字符串类型的日期如何比较大小
- 实现strcmp(字符串比较)
- 【Hibernate】字符串形式的数字如何正确的比较大小
- 如何比较两个时间字符串的大小
- go 比较两个字符串的版本号大小
- php实现比较两个字符串日期大小的方法
- 使用strcmp()函数比较字符串
- Java字符串转换为日期和时间比较大小
- sqlserver2000中字符串类型的日期如何比较大小
- Java字符串转换为日期和时间比较大小