Put into an array

This is a discussion on Put into an array within the C++ Programming forums, part of the General Programming Boards category; I have a database which has quite a few entries which looks like this: module 1¦version 1¦description 1¦command 1 module ...

  1. #1
    Registered User cyberCLoWn's Avatar
    Join Date
    Dec 2003
    Location
    South Africa
    Posts
    124

    Put into an array

    I have a database which has quite a few entries which looks like this:

    module 1¦version 1¦description 1¦command 1
    module 2¦version 2¦description 2¦command 2

    I used the ¦ character to split the different sections.

    What I am unable to do is read from this database and take everything up until the first ¦ char and put that in an array. Then ignore the ¦ char and take everything up until the next ¦ char and put it into another array and so forth.

    Any ideas how to do this or am I going about this in the wrong way?

  2. #2
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    A database or a file?

    If it's a file, then you can read a line and tokenize it using strtok().

  3. #3
    Registered User cyberCLoWn's Avatar
    Join Date
    Dec 2003
    Location
    South Africa
    Posts
    124
    It's a file.

  4. #4
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    You could also use istream.get() to read one character at a time, and then just ignore the '|'.

  5. #5
    Registered User cyberCLoWn's Avatar
    Join Date
    Dec 2003
    Location
    South Africa
    Posts
    124
    An example?

  6. #6
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    The long way around the horn.
    Code:
    int ch;
    
    while((ch = ifstream_var.peek()) != EOF)
    {
         if(ch == '|')
             take an action
          
         ifstream_var.your_get_method
    }
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  7. #7
    Registered User cyberCLoWn's Avatar
    Join Date
    Dec 2003
    Location
    South Africa
    Posts
    124
    Kay I'm real confused. I've never worked with reading something from a file before.

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I've never worked with reading something from a file before.
    It's the same as reading from cin except you have to open the stream yourself.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 08:25 PM
  2. put number in array
    By nevrax in forum C Programming
    Replies: 26
    Last Post: 03-27-2007, 05:20 PM
  3. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 01:04 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. mode of an array
    By Need Help in forum C Programming
    Replies: 15
    Last Post: 09-17-2001, 09:03 AM

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