一只敏捷的棕色狐狸跳到了一只懒狗身上。
据说该句是包含所有26个字母的最短的句子。
MSDN2001
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 );
}
#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;
}
#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;
}