Thread: problem reading mixed data...

  1. #1
    Registered User
    Join Date
    Nov 2006

    problem reading mixed data...

    I can't figure out how to read mixed integer and float data from a text file. I would like to use sscanf if possible but can't figure out how to read in the numerical data.

    An example of the file looks like this:

    Billy 6.0 8.0
    Bob 20 40
    Maynard 0.69 0.98
    Bubba 0 10
    Bunch 1 7

    I would like to be able to write the numerical data out to a file in floating point format and ignore the names.

    Thanks in advance!

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Northern Virginia/Washington DC Metropolitan Area
    Read it all in as float values. You can use sscanf to safely read and convert "60" into a float just fine.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Sep 2001
    Do you strictly need to read in ints as ints?
    scanf("%s%f%f", name, &value1, &value2);
    Callou collei we'll code the way
    Of prime numbers and pings!

  4. #4
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Cambridge, UK
        sscanf(temp,"%s %f %f",name,&num1,&num2);


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-02-2009, 07:27 AM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM
  4. reading data from disk into array problem
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 05-01-2002, 03:19 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM