Thread: Extracting Data from txt File

  1. #1
    Registered User
    Join Date
    Jan 2015
    Posts
    1

    Extracting Data from txt File

    Hi I managed to read txt files and printing them on the console window. I was given a task to select and sample a certain amount of data.

    Example of txt file:

    Voltage (V),Current (I),Power (W)
    50,2,100,
    51,2,102,
    52,2,104,

    etc.. How can I display only the column of Voltage and Power?

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Use fgets() to read data from the file, into a string (array of char). First time, check that the line contains the three labels separated by commas. Subsequently, possibly in a loop, check that there are three values separated by commas, with a comma at the end of the line and extract the data you need (first and third of each set of three values).

    Look up functions like sscanf() or strtok() for interpreting contents of the string.

    And, no, I'm not going to provide sample code. I've given you a few pointers. Writing software is about problem solving, so you need to demonstrate some effort to solve simple problems like this.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extracting data from a .p3d file - is it feasible?
    By shrink_tubing in forum C++ Programming
    Replies: 10
    Last Post: 06-26-2010, 10:39 AM
  2. extracting and printing data from a .dat file
    By z0diark in forum C Programming
    Replies: 3
    Last Post: 11-16-2009, 05:07 PM
  3. SelectNodes (Extracting data XML File)
    By robben in forum C++ Programming
    Replies: 19
    Last Post: 01-07-2007, 12:38 PM
  4. extracting data from file putting it into an array..
    By Cat00 in forum C++ Programming
    Replies: 4
    Last Post: 03-30-2005, 02:48 PM
  5. Replies: 2
    Last Post: 03-03-2004, 07:25 PM