Thread: Read numbers from text file and assign to variables?

  1. #1
    Registered User
    Join Date
    Apr 2020
    Posts
    1

    Read numbers from text file and assign to variables?

    I have a text file which will contain a mock record of imaginary people and in said record I have 3 numbers which I have to find an average of everytime I read and print the text file. I was wondering the best way to do this as I can not figure it out. Picture posted of text file format.

    Read numbers from text file and assign to variables?-screenshot_1-png

    When I print the text file, because I need it in a specific tabulated format I print it character by character using this:
    while ((ch = fgetc(pRead)) != EOF)
    {
    putchar(ch);
    }

    and when it saves the data there are different numbers of spaces between saved records.
    Last edited by Metamooth; 04-21-2020 at 11:42 AM.

  2. #2
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    Read about fscanf().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 12-08-2011, 05:30 AM
  2. Read numbers from a text file
    By fred_maes in forum C Programming
    Replies: 5
    Last Post: 08-13-2011, 06:43 PM
  3. How to read text file into variables
    By Ankur Arora in forum C Programming
    Replies: 1
    Last Post: 05-11-2011, 01:26 AM
  4. Getting variables and numbers from a text file.
    By snoikey in forum C Programming
    Replies: 29
    Last Post: 07-13-2010, 07:26 AM
  5. Read variables and stuff from a text file
    By ChrisJ in forum C++ Programming
    Replies: 1
    Last Post: 06-26-2003, 11:06 AM

Tags for this Thread