---
title: "strcmp函数实现"
author: "holoblog"
date: "2007-12-15T11:08:00Z"
tags: []
slug: "strcmp"
draft: false
lastmod: "2011-11-11T11:23:24Z"
id: 1252033
url: "https://holoblog.iteye.com/blog/1252033"
---

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)intStrCmp(constchar\*des,constchar\*src)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)intc;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if(des==NULL||src==NULL)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)throw"NULLpoint";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)intlen1=strlen(des);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)intlen2=strlen(src);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if(len1!=len2)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)returnlen1-len2;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)while(\*des!='/0')  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if((c=(\*des++-\*src++))!=0)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)returnc;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)returnc;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

测试用例：

1.字符串为AscII串，并且src和des不为空，测试中以src和des长度分类

2.字符串为高AscII串.....

3.字符串为DBCS串

4.字符串中包含DBCS和ASCII

5.src或者des为NULL

6.src和des为""