Thread: Importing arrays from files

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    98

    Importing arrays from files

    How can I import data from a text file into a two-dimensional array?
    Example Data would be
    A.01 C Song 1
    B.01 C Song 2
    B.02 G Song 2.1
    etc.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Use fgets() to read each line.
    Use sscanf() or other string functions to parse the line and extract data into the row elements of your 2D array.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    98
    Could you perhaps give me some code examples?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    I could, but there are umpteen examples on the board already, and I think you need to spend longer than 5 minutes before asking for more help.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  2. I Need To Know Some Things That I Can Put Into A Batch File
    By TheRealNapster in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-20-2003, 08:12 PM
  3. Saving and Importing text files
    By ColdFire in forum Windows Programming
    Replies: 4
    Last Post: 06-17-2002, 08:32 AM
  4. Using c++ standards
    By subdene in forum C++ Programming
    Replies: 4
    Last Post: 06-06-2002, 09:15 AM
  5. reinserting htm files into chm help files
    By verb in forum Windows Programming
    Replies: 0
    Last Post: 02-15-2002, 09:35 AM