how to detect the null line?

This is a discussion on how to detect the null line? within the C Programming forums, part of the General Programming Boards category; file1 Code: AB CD EF aim to process file1 , 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
    21,647
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,647
    Eh, but the first character of those lines in question would be a space, not a null or newline character.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 01: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21