The quick brown fox jumps over the lazy dog.

本文介绍了使用 C 语言中的 `strcmp` 和 `_stricmp` 函数进行字符串比较的方法,并通过实例展示了如何在不同场景下应用这些函数。此外,文章还提供了一个简单的 C 程序来计算字符串大小,帮助理解字符串操作的基础知识。
http://v.youku.com/v_show/id_XMTA4ODEwNjM2.html

The quick brown fox jumps over the lazy dog.
一只敏捷的棕色狐狸跳到了一只懒狗身上。
据说该句是包含所有26个字母的最短的句子。

1句9词26字-----------微软MSDN中常用来做各种字符串比较操作的例子。

MSDN2001
Example
/*  STRCMP.C  */

#include < string.h>
#include <stdio.h>

char string1[] =  " The quick brown dog jumps over the lazy fox ";
char string2[] =  " The QUICK brown dog jumps over the lazy fox ";

void main(  void )
{
     char tmp[ 20];
     int result;
     /*  Case sensitive  */
    printf(  " Compare strings:\n\t%s\n\t%s\n\n ", string1, string2 );
    result = strcmp( string1, string2 );
     if( result >  0 )
        strcpy( tmp,  " greater than " );
     else  if( result <  0 )
        strcpy( tmp,  " less than " );
     else
        strcpy( tmp,  " equal to " );
    printf(  " \tstrcmp:   String 1 is %s string 2\n ", tmp );
     /*  Case insensitive  */
    result = _stricmp( string1, string2 );
     if( result >  0 )
        strcpy( tmp,  " greater than " );
     else  if( result <  0 )
        strcpy( tmp,  " less than " );
     else
        strcpy( tmp,  " equal to " );
    printf(  " \t_stricmp:  String 1 is %s string 2\n ", tmp );
}
Output
Compare strings:
The quick brown dog jumps over the lazy fox
The QUICK brown dog jumps over the lazy fox
strcmp:   String 1 is greater than string 2
_stricmp:  String 1 is equal to string 2

 

// demo.cpp

#include<iostream>
using  namespace std;

int main()
{
                 // 01234567890123456789012345678901234567890123==45
     char slang[]= " The quick brown fox jumps over the lazy dog. ";

    cout<< " sizeof(slang)== "<< sizeof(slang)<<endl;

    cin. get();

     return  0;
}

转载于:https://www.cnblogs.com/shanzy/archive/2012/09/03/2668144.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值