Thread: Help - Basic String Reversal Program

  1. #16
    Registered User
    Join Date
    Sep 2010
    Posts
    25
    Okay, thank you for your comments; but, I didn't have any questions about my code. Three-fourths of that program are a direct copy from the example. What little I changed of it; well, most of those changes are a mimicking of the other parts of the example.

    Points number 1 to 5 on your response are pretty much covered by the printout of the example code in K&R's C.

    This stuff you're telling me not to do: it's done, right here in the example, by the people who put this book together. I'm going to stick with their way for now. I'm not an expert, but my annotated copy of K&R is falling apart at the bindings. The program compiles and works; it's an answer to a chapter 1 problem.

    For point 6, the function reverse strips the newline because I used a frequently re-used function "getline" which adds one in. The only time the newline needs to come out of the string for that program is when the string is printed reversed. That getline function is used dozens of times throughout the book and the exercises; I just re-use it, as is. So, I tailored the reverse function to fit the answer to the problem. This helps support a copy/paste of the function, later.

    One of the unwritten lessons of this book is that in order to get some of the later examples to work, you have to add this function in; its full text is not always provided in later examples. It comes up a lot. It's pretty noticeable in this book. I haven't counted, but if it was used 50 times in here, I wouldn't be surprised. I feel more comfortable with it the way it is.

    Thanks for your feedback.
    Last edited by agxphoto; 01-12-2011 at 10:13 PM.

  2. #17
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Hi agxphoto...

    I would caution you about "appeal to authority" with books such as the K&R C manual. I don't even want to guess how often I've found errors in both text and samples from the tutorials. Also you should note that book was written well before the current C-99 standards came into effect and thus tends to tout "ancient wisdom".

    Most of the voices here are those of experience... you would do well to listen.

  3. #18
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by agxphoto
    Points number 1 to 5 on your response are pretty much covered by the printout of the example code in K&R's C.

    This stuff you're telling me not to do: it's done, right here in the example, by the people who put this book together. I'm going to stick with their way for now. I'm not an expert, but my annotated copy of K&R is falling apart at the bindings. The program compiles and works; it's an answer to a chapter 1 problem.
    If you never attempt to understand points made by others on the pretext that you are not an expert and the book does it that way (if we can be sure that you even copied the book correctly), then you will forever remain a beginner, only able to parrot examples given by your betters.

    Stuff like anduril462's point #1 is understandable: you're looking at an outdated example that should still work, so that's fine. #2 is subjective, e.g., consider that the standard fgets also appends the newline if it is read. But #3 to #5 raise valid issues. Stating that the "program compiles and works" is only a starting point because a program that triggers undefined behaviour might still "work", yet be incorrect.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  3. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  4. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM