-
MMMHUHU
strcmp函数是比较两个字符串的大小,返回比较的结果。一般形式是:i=strcmp(字符串,字符串);①字符串1小于字符串2,strcmp函数返回一个负值;②字符串1等于字符串2,strcmp函数返回零;③字符串1大于字符串2,strcmp函数返回一个正值;strcpy函数用于实现两个字符串的拷贝。一般形式是:strcpy(字符中1,字符串2)其中,字符串1必须是字符串变量,而不能是字符串常量。strcpy函数把字符串2的内容完全复制到字符串1中,而不管字符串1中原先存放的是什么。复制后,字符串2保持不变。
-
郎朗坤
Example of strcmp/* 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" );elsestrcpy( tmp, "equal to" );printf( "\tstrcmp: String 1 is %s string 2\n", tmp );/* Case insensitive (could use equivalent _stricmp) */result = _stricmp( string1, string2 );if( result > 0 )strcpy( tmp, "greater than" );else if( result < 0 )strcpy( tmp, "less than" );elsestrcpy( tmp, "equal to" );printf( "\t_stricmp: String 1 is %s string 2\n", tmp );}OutputCompare strings:The quick brown dog jumps over the lazy foxThe QUICK brown dog jumps over the lazy foxstrcmp: String 1 is greater than string 2_stricmp: String 1 is equal to string 2Example of Strcpy/* STRCPY.C: This program uses strcpy* and strcat to build a phrase.*/#include <string.h>#include <stdio.h>void main( void ){char string[80];strcpy( string, "Hello world from " );strcat( string, "strcpy " );strcat( string, "and " );strcat( string, "strcat!" );printf( "String = %s\n", string );}OutputString = Hello world from strcpy and strcat!
-
繁华开满天机
strcmp是比较2个字符串,如果一样的话,就等于0.如果第一个大于第二个就为1,都则就为-1.strcpy是复制字符串。将达尔戈字符串复制到第一个中去。
-
饮歌长啸
这两个函数都是字符串操作函数。strcmp(char *str1,char *str2)是比较两个字符串,如果str1<str2返回负数,str1=str2返回0, str1>str2返回正数。strcpy(char *str1,char *str2)是复制字符串str2的内容到str1中。
-
守候你守候我
strcmp 对2个字符串str1,str2进行比较 是一个字符一个字符的进行比较返回结果 大小比较<0 str1 小于str2= 0 str1 等于str2> 0 str1 大于str2strcpy (str2,str1) 是复制字符str1 到str2 并且在字符串str2后面加字符串结束符'\0'