Reading til end of line

This is a discussion on Reading til end of line within the C++ Programming forums, part of the General Programming Boards category; Ok I have a data file that say looks like xyzyyxyyzyzyxy zxyzxyzxyzyxzyxzyxyzy zxyzxyzyxyzxyzyxzyxyzxyzyxyzyx yxzyxz zxyzxyzyx I want to read in ...

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    68

    Reading til end of line

    Ok I have a data file that say looks like

    xyzyyxyyzyzyxy
    zxyzxyzxyzyxzyxzyxyzy
    zxyzxyzyxyzxyzyxzyxyzxyzyxyzyx
    yxzyxz
    zxyzxyzyx

    I want to read in each letter as a char and store it into a array

    I want to do this for each line then do something with the array.

    then read in the next line and repeat the process til end of file.

    How can I make it read to the end of the line then stop

    Or could I make an array say

    int temp[255];

    and while values are read into the array I could keep a count then I would know how many letters there are...but will this stop at the end of each line?

    Sorry if this is convoluted thought ill try to clarify if you are lost

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Compare each character as you read it until the newline character is hit - then you are at end of line.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    68
    so something like

    Code:
    myIn >> char;
    
    while (char != '\n')
    {
    myIn >> char;
    }

  4. #4
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    That looks good.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  5. #5
    Registered User
    Join Date
    Sep 2009
    Posts
    68
    Awesome thanks much Dino

  6. #6
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Quote Originally Posted by bleuz View Post
    Awesome thanks much Dino
    Now, that was typed incorrectly... should have been

    Quote Originally Posted by bleuz View Post
    Thanks much, awesome Dino
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. Adventures in labyrinth generation.
    By guesst in forum Game Programming
    Replies: 8
    Last Post: 10-12-2008, 02:30 PM
  3. Replies: 1
    Last Post: 05-21-2006, 12:17 AM
  4. Removing end of line marker
    By rajabadsha in forum C Programming
    Replies: 5
    Last Post: 05-13-2006, 02:24 PM
  5. Replies: 3
    Last Post: 04-27-2005, 12:50 PM

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