Thread: Reading til end of line

  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
    Chappell Hill, Texas
    Posts
    2,332
    Compare each character as you read it until the newline character is hit - then you are at end of line.
    Mainframe assembler programmer by trade. C coder when I can.

  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
    Chappell Hill, Texas
    Posts
    2,332
    That looks good.
    Mainframe assembler programmer by trade. C coder when I can.

  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
    Chappell Hill, Texas
    Posts
    2,332
    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
    Mainframe assembler programmer by trade. C coder when I can.

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, 01:30 PM
  3. Replies: 1
    Last Post: 05-20-2006, 11:17 PM
  4. Removing end of line marker
    By rajabadsha in forum C Programming
    Replies: 5
    Last Post: 05-13-2006, 01:24 PM
  5. Replies: 3
    Last Post: 04-27-2005, 11:50 AM