递归函数1)strcmp 2)反转一个字符串 [英] recursive functions of 1)strcmp 2)reverse a string

查看:89
本文介绍了递归函数1)strcmp 2)反转一个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要两个递归函数

1)第一个必须完成strcmp的工作

我想给我一些关于这个的提示例如我应该比较每个字符串的第一个字符并返回结果?还是所有人物? strcmp如何工作?


2)第二个必须打印一个字符串作为参数反向传递

我试一试,但它没有打印我的第一个character

展开 | 选择 | Wrap | 行号

解决方案


我需要两个< b>递归函数

1)第一个必须完成strcmp的工作

我想给我一些关于这个的提示,例如我应该做什么比较每个字符串的第一个字符并返回结果?还是所有人物? strcmp如何工作?


2)第二个必须打印一个字符串作为参数反向传递

我试一试,但它没有打印我的第一个character

展开 | 选择 | Wrap | 行号



1. strcmp如何工作。


你如何比较两个字符串?


如果你找到两个长度不同的字符串,当你没有这些字符时,你会不会比较每个字母字符串会是一样的吗?


我认为你可以比喻从这里开始吧。


现在,在此之后(抱歉,如果我听起来很粗鲁)你能告诉我strcmp的工作原理吗?


Savage



谢谢,但我认为strcmp不会比较字符串长度的两个字符串。


编辑:我发现这个关于strcmp的返回

大于零的值表示第一个不匹配的字符在str1中的值比在str2中的值更大


我会试一试


关于第二个的任何人?



谢谢但我认为strcmp不能比较字符串长度的两个字符串。



它将一个字符串中的每个字母与第二个字符串中的相应字母进行比较,但前提是长度相等。


野蛮


I need two recursive functions
1) the first must do the job of strcmp
I want to give me some tips about this such as example what am i supposed to compare the first character of each string and return the result? or all the characters? how strcmp works?

2)the second must print a string passed as an argument reverse
I make a try, but it does not print me the first character

Expand|Select|Wrap|Line Numbers

解决方案

I need two recursive functions
1) the first must do the job of strcmp
I want to give me some tips about this such as example what am i supposed to compare the first character of each string and return the result? or all the characters? how strcmp works?

2)the second must print a string passed as an argument reverse
I make a try, but it does not print me the first character

Expand|Select|Wrap|Line Numbers


1.How strcmp works.

How do you compare two strings?

If you find two strings that have different length,would you bother comparing each letter when there is NO WAY that those string would be the same?

I think that you can figure it out from this.

Now,after this(sorry,if I sounded rude) can you tell me how strcmp works?

Savage

Thanks but i think that strcmp don''t compare the two strings with base the length of the strings.

edit:i find this about the return of strcmp
A value greater than zero indicates that the first character that does not match has a greater value in str1 than in str2

I will make a try

Anyone about the second?


Thanks but i think that strcmp don''t compare the two strings with base the length of the strings.

It compares each letter from one string with corresponding letter from the second string,but only if lengths are equal.

Savage


这篇关于递归函数1)strcmp 2)反转一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆