strcpy函数在c语言的作用是什么,strcmp函数、strcpy函数在c语言中的作用

strcmp函数、strcpy函数在c语言中的作用

关注:292  答案:6  信息版本:手机版

解决时间 2019-01-14 07:52

做自己de王妃

2019-01-14 02:00

strcmp函数、strcpy函数在c语言中的作用

最佳答案

雾月

2019-01-14 03:23

strcmp函数是比较两个字符串的大小,返回比较的结果。一般形式是:

i=strcmp(字符串,字符串);

①字符串1小于字符串2,strcmp函数返回一个负值;

②字符串1等于字符串2,strcmp函数返回零;

③字符串1大于字符串2,strcmp函数返回一个正值;

strcpy函数用于实现两个字符串的拷贝。一般形式是:

strcpy(字符中1,字符串2)

其中,字符串1必须是字符串变量,而不能是字符串常量。strcpy函数把字符串2的内容完全复制到字符串1中,而不管字符串1中原先存放的是什么。复制后,字符串2保持不变。

全部回答

1楼酒安江南

2019-01-14 08:05

strcmp 对2个字符串str1,str2进行比较 是一个字符一个字符的进行比较

返回结果 大小比较

<0 str1 小于str2

= 0 str1 等于str2

> 0 str1 大于str2

strcpy (str2,str1) 是复制字符str1 到str2 并且在字符串str2后面加字符串结束符'\0'

2楼西风乍起

2019-01-14 06:40

strlen(测字符串长度):strlen(字符数组) strcpy(字符串复制):strcpy(字符数组1,字符串2),将字符串2复制到字符数组1中去 strcmp(字符串比较):strcmp(字符串1,字符串2),如果字符串1=2,函数值为0;如果字符串1>2,为正整数;如果字符串1<2,为负整数 strcat(字符串连接):strcat(字符数组1,字符数组2),把字符串2放到1的后面,结果放在1中

3楼不想翻身的咸鱼

2019-01-14 05:40

strcmp是比较2个字符串,如果一样的话,就等于0.如果第一个大于第二个就为1,都则就为-1.

strcpy是复制字符串。将达尔戈字符串复制到第一个中去。

4楼鸽屿

2019-01-14 04:45

Example of strcmp

#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;

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 );

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

Example of Strcpy

#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 );

}

Output

String = Hello world from strcpy and strcat!

我要举报

如以上问答内容为色情/暴力/低俗/不良/侵权等信息,可以点下面链接进行举报,我们会做出相应处理,感谢你的支持!

大家都在看

推荐资讯

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值