CompuServe Thread

#C recursion

9 messages in this thread
#59500From: paulMar 18, 1987 11:54 PM
I started to learn C two weeks ago and as I was playing with recursion, I made a very simple program that would point to a string and that would print it backward. But for some unknown reason, It doesn't work. here is the program : char str[] = "paulo"; reverse(s) /* reverse string s */ char t[6]; char s[]; static int x; { main() if (*s != '\0') { { reverse(++s); reverse(str); t[x++] = *s; printf ("%s",t); } } } It seems that when it gets to the end of string character, it goes through the program but never pops out the pointer to the end of the string. I did the same program but instead of using pointers I used characters and it worked fine. When it got to the end of string character, It would go through the program, pop out the character and start going back through the recursion with the previous character. Anybody has any idea why it does this. HELP !!!!
#59501From: Don Curtis/SYSOPMar 19, 1987 12:23 AM
Paul, Your message came out so garbled that it is impossible to make heads or tails of it.. Trying to reconstruct it from what is visible, it appears that you are attempting to define a function within another function…which just doesn't work…and probably isn't what you are trying to do, but is how it came out after being re-formatted. Re post your code, and at the start of each line of code, put a period as the first character on each line as you type it into CIS, that will force each line to be printed on a new line as this line is separated from above —a period goes here (you can't see it since it is a format command) Also, we require full names here, so after reading this, please go back to the main Forum menu or function prompt, select OP and then from the next menu, select Change Name and enter your first and last name. Thanks Don
#59773From: Brian NiessenMar 20, 1987 9:57 PM
Dave, why not just tell him to use SU (Save Unformatted) . . It allows me to do things like this without periods all over the place. . .Bri
#59779From: John DraperMar 20, 1987 10:07 PM
he did not say to use SU because it makes a terrible mess of screens that are less characters wide than the one in which you left the message. In other cases, it may look a bit silly to have the message all over in the left part of the screen. It is a far better solution to leave the message unformatted except for the parts that absolutely need to be. Regards, Larry.
#59798From: Brian NiessenMar 20, 1987 11:29 PM
Yes, but for listings, SU is neater, and easier than remembering or editing a file for uploading to put .'s on each line. bri s
#59791From: Don Curtis/SYSOPMar 20, 1987 10:40 PM
Bri, Well you answered me (but called me Dave???) but we prefer not to use SU because the screen won't get re-formatted for the various terminal widths. With the dot commands, re-formatting will still occur and folks using the various terminal widths will all see it just fine, but those messages saved via SU could show up weird on other terminals. For example (Bri–I know you know this, it for others reading this thread), if I save this message using the SU command and someone comes on with a 60 column terminal, the lines will all get chopped at 60 characters and there will be a 2nd line 20 characters long under it—sort of a stutter step;whereas, if I save it with the Store command…folks with 60 column terminals will see the paragraphs as normal. Don
#59800From: Brian NiessenMar 20, 1987 11:31 PM
Don, I agree, but for Listings, SU is handier. Bri (Sorry for the Dave, Don)
#59803From: John DraperMar 20, 1987 11:48 PM
Handier, easier, but not the best solution, unless it is a listing with no associated text. Regards, Larry.
#59905From: BILL LEACHMar 21, 1987 2:19 PM
Bri: I think that the line length can become a problem. Your first line would have been too long for some 'terminals.' I think that the leading period still lets CIS wrap the lines where SU does not. 73s, bill