strcpy在c语言中的表达,strcmp函数、strcpy函数在c语言中的作用?

本文介绍了C语言中strcmp函数进行字符串比较的案例,展示了大小写敏感和不敏感的比较结果,并展示了strcpy和strncpy用于字符串复制的实用示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

4c729a3037569d584f332b083fc95cac.png

郎朗坤

Example of strcmp/* STRCMP.C */#include #include 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 #include 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!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值