Help with Recursive Function with String (C) - Programming - HWzone Forums
Skip to content
  • Create an account
  • About Us

    Hello Guest!

     
    Please note - in order to participate in our community, comment and open new discussions, you must join as a registered member.

    Our members enjoy many advantages, including the ability to participate in discussions, enjoy raffles and promotions for members of the site, and receive our weekly content directly by email.

    Do not like being harassed by email? You can register for the site but do not submit your registration to the weekly email updates.

Help in recursive function with string (C)


Recommended Posts

Peace,
I'm already really desperate so would love to help with the question (C language).
I need to write a recursive function (without pointers) that picks up a string for an array (up to 100 characters) and prints it in reverse order and only the letters without the characters.
Thank you!

Post Reply Direct Link To This Post
Share on other sites
Quote by af db creid

Greetings.

 

Well -

A. Should the recursive function itself absorb the text or separately from it?

B. What have you tried so far? What do you need help with?

Need to pick up text from the main and then run the function.

By and large I was able to do it without an array. The problem is that there is a limit to 100 characters so I'm pretty sure the only way is in the array.

Edited By lina12
Post Reply Direct Link To This Post
Share on other sites

I could not understand the exercise.

Do you have an array of 100-character char?

So:

tank szInput[100];

No ?

Recruiting means that the function can call itself. So suppose the function calls itself up to a certain condition, for example an exit or enter character or something similar.

If so the array needs to be global to maintain its values ​​and probably needs another variable that will hold the length.

But you say something else that does not work, the function gets the characters ...? I came out a little confused

Post Reply Direct Link To This Post
Share on other sites
Quote of Jabberwock

I could not understand the exercise.

Do you have an array of 100-character char?

So:


tank szInput[100];

No ?

Recruiting means that the function can call itself. So suppose the function calls itself up to a certain condition, for example an exit or enter character or something similar.

If so the array needs to be global to maintain its values ​​and probably needs another variable that will hold the length.

But you say something else that does not work, the function gets the characters ...? I came out a little confused

I need to pick up the characters first, then activate the function and change their order and only pick up the letters without the numbers and characters that can be in the array. Mostly it is not clear to me what is done within the function with the array. How do you print and how do you receive?

Edited By lina12
Post Reply Direct Link To This Post
Share on other sites
Quote from lina12

And absorb only the letters without the numbers and characters that can be in the array

A character can be either a number or a letter or a special character such as a dollar, an asterisk, etc.

I did not understand your sentence

Post Reply Direct Link To This Post
Share on other sites
Quote of Jabberwock

A character can be either a number or a letter or a special character such as a dollar, an asterisk, etc.

I did not understand your sentence

True, but I need to print out only the characters that are letters from the array.

Post Reply Direct Link To This Post
Share on other sites
Quote from lina12

True, but I need to print out only the characters that are letters from the array.

I realised. Okay so in order to know how to do this condition one has to know the ASCII table.

https://he.wikipedia.org/wiki/ASCII

http://www.asciitable.com/

As you can see from the table, uppercase letters A to Z are arranged one after the other and the lowercase letters as well, so to check if we received a letter, do the following:

int main()
{
    tank wave;
    China >> wave;
    
    if (wave >= 'A' && wave <= 'Z' || wave >= 'at' && wave <= 'z')
        cout << "yes we got a letter and not a number";
    else cout << "we did not get a letter!";
}

 

Post Reply Direct Link To This Post
Share on other sites
Quote of Jabberwock

I realised. Okay so in order to know how to do this condition one has to know the ASCII table.

https://he.wikipedia.org/wiki/ASCII

http://www.asciitable.com/

As you can see from the table, uppercase letters A to Z are arranged one after the other and the lowercase letters as well, so to check if we received a letter, do the following:

int main()
{
    tank wave;
    China >> wave;
    
    if (wave >= 'A' && wave <= 'Z' || wave >= 'at' && wave <= 'z')
        cout << "yes we got a letter and not a number";
    else cout << "we did not get a letter!";
}

 

You will learn how to use the standard library! An important skill!

#include  // or for C ++
  
isalpha(ch)

 

Post Reply Direct Link To This Post
Share on other sites
Quote by af db creid

Good.

First of all - what have you tried. It's easiest to give you a plan ready, but it's more helpful to you if we guide you. What are your directions? what did you think about?

What does "without voters" mean? But how? With arrays?

Should be done with arrays. By and large I was able to do it without an array. But when I tried to turn it into an array everything got confused there. And the thing with the letters I know how to do I just can not arrange it so that it will run properly.

Edited By lina12
Post Reply Direct Link To This Post
Share on other sites
Quote by af db creid

What code did you try?

I got an array for the function. I calculated the function in the 0th limb and each time I advanced the array by 1 (i.e. array + 1)

And I put the print command at the end.

Post Reply Direct Link To This Post
Share on other sites

Join the discussion

You can then join the discussion and then join our community. If you already have an account with us, please Log in now To comment under your username.
Note that: The comment will appear to the surfers after approval by the board management team.

guest
Add a comment

×   The content pasted is with formatting.   Remove formatting

  Only 75 emoji are allowed.

×   Your link has been automatically assimilated.   Show as regular link

×   Your previous content has been automatically restored.   Clear all

×   You can not paste images directly. Upload or insert images from URL.

×
  • Create new ...

At the top of the news:

new on the site

You have an update

You have an update

Buzz Zone: The Instagram spaces #buzzzone You have an update A photo posted by HWzone.co.il (@ hwzone.co.il) on 2021-01-20 16:09:29 You have an update