Reading from tab-delimited file

This is a discussion on Reading from tab-delimited file within the C Programming forums, part of the General Programming Boards category; Hi everyone, I am currently trying to put together a program that runs dijkstra's algorithm, this is not the problem ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    12

    Reading from tab-delimited file

    Hi everyone,
    I am currently trying to put together a program that runs dijkstra's algorithm, this is not the problem however. The program must first read in data from a tab delimited file, the format of the file is:

    string <tab> string <tab> integer

    This line is repeated with different values 29 times down the page.

    I was wondering if there is a function i could use to read this information in. I then want to store the info. in an array of a data structure.

    Thankyou for your time....
    Ben

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,535
    Use fgets() to read each line
    Use strtok() to break the line up into each tab-delimited string, and copy those to your struct.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-02-2009, 06:27 AM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 02:58 PM

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