Thread: Line of data input method

  1. #1
    Registered User
    Join Date
    Apr 2009

    Line of data input method

    Hello all,

    I'm new to C programming, and I have this programming assignment that I've been working on for days. I'm trying to use this line of data input method.

    Instead of asking for each value separately, your program may ask the user to enter all the information for one exercise on the same line. This data would be an integer for exercise code, a one word string for exercise name, a char for type of exercise, body part focus, equipment needed, and equipment setting, an integer for recent setting and target setting, a char for exercise measurement, an integer for recent measurement and target measurement, and a floating point number for time per measurement. You must tell the user exactly how to enter the line of data. The data for a single exercise will be entered by the user as twelve values on one line as follows {there must be one space only between the values}:

    > 053 Machine_Bicep_Curl S A W W 30 50 0 10 18 3.25 300 15 5

    which represents the Machine Bicep Curl (053), a 'S'trength exercise for 'A'rms using a 'W'eight machine. Its setting is 'W'eight with a recent value of 30 and a target weight of 50. Its measurement is Repetitions (indicated by the 0) with a recent measurement of 10 reps and a target of 18. An average Machine Bicep Curl takes 3.25 seconds. The maximum length of time this exercise should be done is 300 seconds (5 minutes). Negative results start occurring at 15% time over 300 seconds (45 seconds) and the dropoff in effectiveness for an additional 45 seconds over max is 5%.

    Your program will read the elements on the input line and store them in the appropriate members of the current struct variable you have allocated. Your program should read in as many lines of input for exercises as the user enters until the user indicates that they are finished.

    The information of one of the data from in my struct is as follows:

    Exercise code The integer numeric code associated with a particular exercise. For this lab we are using strings but we will also still have exercises that are coded by number (ex. Recumbent Exercise Bike = 004, Free Weight Fly = 132, Yoga Sun Salutation = 488, etc.). All the other pieces of data associated with this exercise are also declared in the struct.

    Here's my struct that I created, but I had left out the rest of my program

    struct program{
            int exercise_code;      //The integer numeric code that is associated with a particular exercise
            char *exercise_name;    //The name as string with a particular exercise
            char type_of_exercise;  //The single character to hold the letter code for the type of exercise
            char body_part_focus;   //The character to hold the letter code for the body part addressed by the exercise
            char equipment_needed;  //The character to hold the letter code for the type of equipment needed for the exercise
            char equipment_setting; //The character code for the setting of the equipment needed for the exercise
            int recent_setting;     //The integer value for the most recent setting used for that particular exercise
            int target_setting;     //The integer value for the target setting for that particular exercise
            enum exmeasurement exercise_measurement;   //List each type of measurement that is valid
            union recent recent_measurements;  //The value of the most recent measurement recoreded for that particular exerci$
            union target target_measurement;   //The value of the target measurement for that particular exercise
            double time_per_measurement; //average time in seconds, and this measurement multiplied by the recent measurement $
            double max_effective_length; //Indicates the maximum length of time that this exercise should be performed during $
            float over_max_increment;    //Indicates the time increments over max that actually lead to reduced results
            float over_max_dropoff;      //Indicates the amount of dropoff results per each overmax increment
            double recent_exercise_length; //The value is time per measurement times recent measurement
            struct program *next; //Pointer called next to point to the next node in the list

    I believe I would use a while loop with if-statements within in order to test the following information, but how would I plug it into my new allocated struct.

    Do I use fprintf?

  2. #2
    Registered User
    Join Date
    Sep 2004
    What's wrong with the advice you got in this thread?

  3. #3
    Registered User
    Join Date
    Sep 2006
    To read in the data from a file, use fscanf() for text files, and fread() for binary files.

    Use fprintf() when you want to write text data, out to a file.

    I believe our poster got tired of messing with a linked list. IMO arrays are just easier to work with, most of the time.

    Larry, post up your code that you have. Do you have the array made, yet?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 05-05-2009, 04:53 PM
  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. Message printing problem
    By robert_sun in forum C Programming
    Replies: 1
    Last Post: 05-18-2004, 05:05 AM
  4. Sorting data retrieved from input file
    By Minds_I in forum C Programming
    Replies: 3
    Last Post: 07-20-2003, 06:25 PM
  5. file input by line
    By VanJay011379 in forum C++ Programming
    Replies: 2
    Last Post: 08-01-2002, 05:44 PM