Ignoring the Tab at the begining of the line..

This is a discussion on Ignoring the Tab at the begining of the line.. within the C++ Programming forums, part of the General Programming Boards category; Ignoring the spaces and the Tab. Hi guys, I am writing a C++ program under Linux, in this program I ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    Lightbulb Ignoring the Tab at the begining of the line..

    Ignoring the spaces and the Tab.

    Hi guys,
    I am writing a C++ program under Linux, in this program I am reading a file, and I want to ignore the Tab and comments ( the line which start by #).

    I solve the problem with the comment lines, but how can I ignore the TAB at the beginning of some lines.
    Code:
    File1.txt
    #This is the first part
    	Command1.  ! subcomment
    	Command2.
    	Command3.
    	Command4  
    #This is the second part
    	Command5   ! subcomment
    	Command6
    #The End.
    Thank you for your help.
    Last edited by NANO; 05-03-2003 at 08:10 PM.
    C++
    The best

  2. #2
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Which method are you using to read the file, C Style or C++ Style?

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    C++

    I am using C++ method.
    C++
    The best

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Post some of what you've tried so far.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117
    use ascii value to check if current char is tab..
    http://www.asciitable.com/
    or u could use isspace() this will check for tab..
    but in the other hand it wil check for space to...
    but u could do double check to see if is really a space or tab..
    just a suggestion..
    Luigi


    // I use Xcode 1.1 && CodeWarrior 8.3
    // When on Mac Os X 10.3.2

    // I use Microsoft Visual C++ 6.0
    // When on windows XP

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>use ascii value to check if current char is tab..
    Better still, just use \t
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    I'm pretty sure that the overloaded operator "<<" for ifstream's eats whitespace. Try it.

  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    Thank you guys.

    Here is a part of my code:
    Code:
    string open( sting file_name)
    /*
    * open the file
    * read the lines one by one
    * delete the comeents ( lines or after the command
    * ignor the TAB at the begining.
    */
    {
    fstrem in_file;
    in_file.open(file_name.c_str(), ios::in)
    
    int lines= 0;
    string code_line;
    
    getline(in_file, code_line);
    while(!in_file.eof())
        //handel Empty lines
        while(code_line.size() == 0 && !in_file.eof()){
           getline(in_file, code_line);
           lines ++;
        }
        
        // handel Comments after the command
        if( line_code.find("!") != -1){
          line_code= line_code.erase(line_code.find("!"), line_code.size());
        }
        // handel comment lines.
        while((strcmp(line_code.c_str)(,"")==) && !in_file.eof()){
           getline(in_file, line_code);
           lines++;
        }
        // reading from the file and ignoring the TAB.
        /*
        I don't know how to do it
        */
        cout<<" Thank you for your help";
        
        //end of function open and read the file
        
    }
    The project is very big but I want the input file to look nice, so I thought about having a TAB, but I end up having this problem.

    I want to learn how to deal with TABs at the begining of the lines for future as well.

    Thank you for your help and support.
    C++
    The best

  9. #9
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Wouldn't searching the file for all occurances of the tab ASCII character and removing them work?

    Edit: Or are they done as individual spaces? In that case...you could run a search for every occurance of (newline) five spaces in a row and replace it with just (newline)
    Away.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading a buffer line by line, while using system read
    By Hammad Saleem in forum C Programming
    Replies: 9
    Last Post: 05-27-2008, 05:41 AM
  2. line number on a rich edit control
    By rakan in forum Windows Programming
    Replies: 1
    Last Post: 02-18-2008, 06:58 AM
  3. Adding Line numbers in Word
    By Mister C in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 06-24-2004, 08:45 PM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

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