Thread: inputting of files and storing to variables

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    12

    inputting of files and storing to variables

    I have to input text from a file and it will be in the following format

    feet or meters
    pressure etc (this shouldnt be too hard)

    I'm thinking of using a for loop with peek() to look ahead so I can get that but my real problem comes when I get to the numers

    (number,number,number)
    (number,number,number) now these points are going to make a (number,number,number) triangle. I need to use pointers I'm pretty sure of that. I dont know how to store the numbers from the text file to a float variable. I can't remember how to use the pointers to keep this process up till I get to the end of the file.

    I've looked through 2 books on it and several pages and found this forum. I hope someone can help me.

  2. #2
    Former Member
    Join Date
    Oct 2001
    Posts
    955
    well, if you're writing the text file in plain text mode, use

    fscanf(myfile,"%lg",&myfloat);

    I'm not really sure if it's %lg, but try it with g, lg, e, le, f, lf and some more

    or if you're writing it in binary, read four bytes and assign them to your variable


    Good luck

    Oskilian

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    12
    thanks for the help. I'll give it a try and come back if I need some more help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Storing Objects in txt files?
    By Swerve in forum C++ Programming
    Replies: 4
    Last Post: 03-15-2009, 12:17 PM
  2. Storing and accessing data from and to .txt files.
    By Glauber in forum C++ Programming
    Replies: 9
    Last Post: 05-27-2008, 02:59 PM
  3. storing integer values in files using WriteFile
    By Fender Bender in forum Windows Programming
    Replies: 1
    Last Post: 01-15-2006, 12:15 AM
  4. Storing images or files inside executable?
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 03-30-2002, 08:31 PM
  5. storing string objects to binary files
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 10-06-2001, 11:33 PM