Thread: Help with progamming assignment

  1. #31
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by awsdert
    Since its an assignment there is the possibility his teacher will throw a different string at it to see how well he programed it, these considerations could be the difference between a C and a A+
    True (and even more so if this were not an assignment!), but christop's point still stands: flp1969's overarching point about checking for edge cases is a good one, but the particular edge case was addressed by the original code due to short-circuit evaluation, so it is of no concern.
    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

  2. #32
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    945
    Quote Originally Posted by awsdert View Post
    Since its an assignment there is the possibility his teacher will throw a different string at it to see how well he programed it, these considerations could be the difference between a C and a A+
    Any string with zero, one, two, three, ... or 1000 characters in it will be handled just fine.* Feel free to put them at the end of a block/page of valid memory with dragons after the null terminator--it won't matter. I'll be impressed if you can give any string that could make it fail.

    *There's no string length limit in the OP's function (other than limits of the execution environment itself), but it's only required to handle strings up to 1000 characters long.

  3. #33
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    Quote Originally Posted by laserlight View Post
    True (and even more so if this were not an assignment!), but christop's point still stands: flp1969's overarching point about checking for edge cases is a good one, but the particular edge case was addressed by the original code due to short-circuit evaluation, so it is of no concern.
    Hummmm... Yes, I missed the short circuit evaluation completely!!!!

  4. #34
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    Quote Originally Posted by christop View Post
    Any string with zero, one, two, three, ... or 1000 characters in it will be handled just fine.* Feel free to put them at the end of a block/page of valid memory with dragons after the null terminator--it won't matter. I'll be impressed if you can give any string that could make it fail.

    *There's no string length limit in the OP's function (other than limits of the execution environment itself), but it's only required to handle strings up to 1000 characters long.
    Ok. I missed the "short ciruit evaluation" completely... but zero length string? In this case *str == *(str+1) will be a compare between a NUL char and garbage. The clever "short circuit" solution will not save you!

  5. #35
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    945
    Quote Originally Posted by flp1969 View Post
    Ok. I missed the "short ciruit evaluation" completely... but zero length string? In this case *str == *(str+1) will be a compare between a NUL char and garbage. The clever "short circuit" solution will not save you!
    Sure, but the test in the while loop will save me! while(*str != '\0'){.

  6. #36
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    Quote Originally Posted by christop View Post
    Sure, but the test in the while loop will save me! while(*str != '\0'){.
    Ahhhhh... of course! Sorry!

  7. #37
    I'm a computer snoopfrogg's Avatar
    Join Date
    Feb 2019
    Posts
    29
    Quote Originally Posted by awsdert View Post
    Since its an assignment there is the possibility his teacher will throw a different string at it to see how well he programed it, these considerations could be the difference between a C and a A+
    She actually gives us a shell script to make sure it passes those conditions, and they do.
    "One of the best programming skills you can have is knowing when to walk away for awhile."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The C Progamming Language Excercise 5-4
    By mekadir in forum C Programming
    Replies: 7
    Last Post: 09-03-2015, 07:05 AM
  2. Help for my assignment!
    By 110abbidi in forum C Programming
    Replies: 5
    Last Post: 08-09-2012, 11:25 PM
  3. Replies: 4
    Last Post: 01-08-2012, 05:31 AM
  4. Replies: 3
    Last Post: 04-26-2009, 08:54 AM
  5. new to c progamming any one can help
    By manalidris in forum C Programming
    Replies: 1
    Last Post: 05-13-2002, 05:05 AM

Tags for this Thread