TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: All
from: Sam Benson
date: 1996-05-27 16:07:56
subject: Understanding recursion

Hi All , hope you are having a nice day

Can some kind person please explain this to me:

If I put line_in = "This is a test string.", why do I get output of

----CUT----
This is a test string.

.gnirts tset a si sih
----CUT----

It keeps dropping the first letter in the last line.

Why?

The bit of code that is doing this is
(with the value passed to index = 0)


void reverse (char line_in[], int index)
{
    if (line_in[index])
    {
        printf ("%c", line_in[index]);
        index++;
        reverse (line_in, index);
    }
    printf ("%c", line_in[index]);
}



I'm using DJGPP 2.0 for a compiler and learning C from it. Yes I know
that is a hard way of doing it, but I'm learnig slowly.

Thank you all.

 -=> Yours sincerely, Sam Benson <=-

--- Terminate 4.00/Pro
* Origin: When did you last warm yourself with a Terminate! (3:640/245.9)
SEEN-BY: 50/99 620/243 623/630 640/151 201 206 216 217 222 230 238 245 247
SEEN-BY: 640/249 281 297 305 309 313 370 375 531 561 820 821 822 823 842 890
SEEN-BY: 640/894 895 937 690/660 711/401 409 410 413 430 808 809 932 934
SEEN-BY: 712/515 713/888 714/906 800/1
@PATH: 640/245 309 201 820 711/409 808 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.