Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So the programm is about reversing a string in two ways, one of them being recursive (i am already aware that recursion isn't the best way to reverse a string).

What I have tried:

<pre>
#include <stdio.h>
}
Posted
Updated 27-May-21 23:08pm
v2
Comments
KarstenK 28-May-21 6:59am    
Download and install Visual Studio or gcc.

As Karsten has said, you should spot this pretty easily with the debugger. How you use it depends on your compiler system, but a quick Google for the name of your IDE and "debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!

I'll give you a hint though: When does this loop exit?
C
while (ende > anfang)
{
    i = *a;
    *a = *e;
    *e = i;

    ++a;
    --e;
}
 
Share this answer
 
Comments
omeretto1 19-May-21 6:18am    
I opted out for an online debugger (i was using Sublime Text 3 as IDE already, but debugging there can be a nightmare). So i am already aware now of the problems and i already fixed the segfault. As for reverseRec i am having trouble understanding what exactly i am supposed to free? in the putBack function there is a malloc so obviously i need to free something, somehow i can't figure out what?
it is clearly a cae to use the debugger and find it out yourself. It would clearly give you the hint where the buggy memory access is and you may fix it yourself.

Read some Debugger tutorial to get a grip on it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900