Thread: how to detect the null line?

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    168

    how to detect the null line?

    file1
    Code:
    AB
    CD
    
    EF
    aim to process file1 , how to detect the null line?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Read line by line until EOF is reached. If the first character of the current line is a null character (or a newline character before its removal if you are using fgets()), then it is a blank line.
    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

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    168
    Quote Originally Posted by laserlight View Post
    Read line by line until EOF is reached. If the first character of the current line is a null character (or a newline character before its removal if you are using fgets()), then it is a blank line.
    I see , thanks.
    moreover if the first character of one line is null, how to be distinguished from the blank line?

    for example:
    file2
    Code:
    AA
      B
    CC
    
    DD
    how to be distinguish? the second line and the fourth line

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Loop through each character in the line then. isspace comes to mind.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Eh, but the first character of those lines in question would be a space, not a null or newline character.
    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

  6. #6
    Registered User
    Join Date
    Aug 2009
    Posts
    168
    Quote Originally Posted by quzah View Post
    Loop through each character in the line then. isspace comes to mind.


    Quzah.
    I do understand, thank you very much !

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked List Not Saving Value as Int
    By bar338 in forum C Programming
    Replies: 4
    Last Post: 05-04-2009, 07:53 PM
  2. Help Debugging my AVL tree program.
    By Nextstopearth in forum C Programming
    Replies: 2
    Last Post: 04-04-2009, 01:48 AM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. button 'message'
    By psychopath in forum Windows Programming
    Replies: 12
    Last Post: 04-18-2004, 09:57 AM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM