zoukankan      html  css  js  c++  java
  • strcmp

    迎接考试中:

    今日必须会的知识:

    1、这是主函数

    //题:比较字符串 
    //要看ASII表 A:65,a:95
    #include<stdio.h>
    #include "1.c"
    int main(void){
    	char a[] = "Aaa";
    	char b[] = "aa";
    	int num = compare(a,b);
    	printf("%d",num);
    }
    

     1、被调用的函数

    #include<stdio.h> 
    int compare(char a[],char b[]){
    	int bLenth,aLenth;//声明 
    	int i = 0,j = 0,k = 0,num = 0;
    	int o;
    	
    	//计算字符数组的长度 
    	while(a[i]!=''){
    		i++;
    	}
    	aLenth = i;//计算字符数组a的长度
    	while(b[j]!=''){
    		j++;
    	}
    	bLenth = j;//计算字符数组b的长度
          //printf("a数组的长度为:%d,b数组的长度为:%d
    ",aLenth+1,bLenth+1); 
          
    	//谁短取谁 
    	if(aLenth>=bLenth){
    		o = bLenth;//aLenth = i;赋值给o; 
    	}else{
    		o = aLenth;//
    	}
    	
    	//	 
    	for(k;k<o;k++){
    		if((int)a[k]>(int)b[k]){//将字符串转换成int型, 
    			return 1;
    		}else if((int)a[k]==(int)b[k]){
    			num++;//
    			continue;
    		}else{
    			return -1;
    		}
    	}
    	
    	//
    	if(num==o){
    		if(aLenth>bLenth){
    			return 1;
    		}else if(aLenth<bLenth){
    			return -1;
    		}
    		else{
    			return 0;
    		}
    	}
    } 
    

    3、 }else if((int)a[k]==(int)b[k]){//我不懂这个。。。

  • 相关阅读:
    php 数组
    条件语句if else ,switch ,while ,do.while
    if..else 判断中的 Boolean()转换
    wampserver 集成环境
    sublime text 安装及使用
    vue tab切换
    SVG 基础
    gitosis管理员的密钥丢失解决办法
    源码安装MySQL
    Xshell远程登录
  • 原文地址:https://www.cnblogs.com/chenduzizhong/p/6025520.html
Copyright © 2011-2022 走看看