Thread: About the Morse code Converter

  1. #16
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by Monster

    Oops.....
    Code:
    line[strlen(line)-1] = '\0'; /* remove newline character */
    Did you read the quote in my post as well though? You can't just blat over the last character, presuming it's a newline, 'cos it might not be.

    A safer way is
    Code:
    if (line[strlen(line)-1] == '\n') line[strlen(line)-1] ='\0';
    This does do 2 calls to strlen() which is a bit of an overhead. Depending on your app, it may be better to do one call, and store the result in another variable, using that in the above code.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  2. #17
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Originally posted by Hammer

    Did you read the quote in my post as well though? You can't just blat over the last character, presuming it's a newline, 'cos it might not be.

    A safer way is
    Code:
    if (line[strlen(line)-1] == '\n') line[strlen(line)-1] ='\0';
    Yes, I did read your quote and I know what you mean. My response was about the first quote you wrote.
    Maybe it was better to respond to both quotes the same time.


    Cheers,
    Monster

  3. #18
    Registered User
    Join Date
    May 2002
    Posts
    10
    Thx a lot guys...you are very helpful
    I'm a rookie

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 23
    Last Post: 04-20-2009, 07:35 AM
  2. Problem : Threads WILL NOT DIE!!
    By hanhao in forum C++ Programming
    Replies: 2
    Last Post: 04-16-2004, 01:37 PM
  3. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. funky little program - word to morse converter!
    By Brian in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 01-18-2002, 04:02 PM