Thread: Trouble Interpreting Column Headers

  1. #1
    young grasshopper jwroblewski44's Avatar
    Join Date
    May 2012
    Location
    Where the sidewalk ends
    Posts
    294

    Trouble Interpreting Column Headers

    In this problem, they have supplied a data sheet ( which is supposedly tab delimited, but not my copy ). In the problem, posted below, they state, "The first row of the file contains the column headings. There are eight selfexplanatory fields." Now I may be dimmer than the students they are used to dealing with, but the titles are somewhat helpful to me, nothing more. Can someone help me interpret the titles meanings'? My goal is determine how many people emigrated from Massachusetts to all the other states. The data sheet is attached. Thanks pals for any and all pointers!

    Problem:

    In this problem, we will be reading in formatted data and generating a report. One of the
    common formats for interchange of formatted data is ’tab delimited’ where each line corresponds
    to a single record. The individual fields of the record are separated by tabs. For this problem,
    download the file stateoutflow0708.txt from Stellar. This contains the emigration of people
    from individual states. The first row of the file contains the column headings. There are eight self
    explanatory fields. Your task is to read the file using fscanf and generate a report outlining the
    migration of people from Massachusetts to all the other states. Use the field ”Aggr AGI” to report
    the numbers. Also, at the end, display a total and verify it is consistent with the one shown below.
    An example report should look like the following:

    STATE TOTAL
    "FLORIDA" 590800
    "NEW HAMPSHIRE" 421986
    ..........
    Total 4609483
    Make sure that the fields are aligned.

    edit: in the actual problem, the output is aligned properly.

    stateoutflow0708.txt
    Last edited by jwroblewski44; 03-07-2013 at 11:06 PM.

  2. #2
    Registered User
    Join Date
    Nov 2011
    Location
    Saratoga, California, USA
    Posts
    334
    State-of-Origin-Code , County-of-Origin-Code , State-Destination-Code , Couny-Destination-Code , State Abbreviation , State Full Name , Number of Tax Returns , Number of Tax Exemptions (Claimed?) , Aggregate-Adjusted-Gross-Income.

    Edit: It appears that the State-Destination-Code is tied to the State-Abbreviation/State-Full-Name.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    In this problem, they have supplied a data sheet ( which is supposedly tab delimited, but not my copy )
    The link you posted is a tab delimited file.
    Now I may be dimmer than the students they are used to dealing with, but the titles are somewhat helpful to me, nothing more. Can someone help me interpret the titles meanings'?
    The titles actually don't mean much of anything to me. What means more to me is the format of the file. This file seems to have the following layout
    string State_Code_Origin, string County_Code_Origin, string State_Code_Dest, string County_Code_Dest, string State_Abbrv, string State_Name, int Return_Num, int Exmpt_Num, and int Aggr_AGI.

    Your task is to read the file using fscanf and generate a report outlining the
    migration of people from Massachusetts to all the other states. Use the field ”Aggr AGI” to report
    the numbers.
    It really seems that the only columns you are interested in are the state names or state abbreviation and the last field, "Aggr AGI".

    So now comes the easy part, writing the program to read the file and report the required information.

    Jim

  4. #4
    young grasshopper jwroblewski44's Avatar
    Join Date
    May 2012
    Location
    Where the sidewalk ends
    Posts
    294
    Thank you very much for the super speedy reply! With your help, I realized the state codes reflect the same states in the "Origin" column as in the "Destination" column. Now to discover how I can use the tax data to determine how many people emigrated. Feel free to shout out the answer!!

  5. #5
    young grasshopper jwroblewski44's Avatar
    Join Date
    May 2012
    Location
    Where the sidewalk ends
    Posts
    294
    The link you posted is a tab delimited file.
    When I go through the file on my computer, I am seeing an extra hidden character before the tabs. I don't know how to easily remove them.

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    That "hidden" character seems to be a space character.

    Jim

  7. #7
    young grasshopper jwroblewski44's Avatar
    Join Date
    May 2012
    Location
    Where the sidewalk ends
    Posts
    294
    Is it present in your copy of the file too? In my opinion, if there is more than a tab in between the entries, it's not really a tab delimited file. As with CSV's, there is a comma and nothing but a comma between the entries. Do you have any ideas on how to extract the number of people moving per record using the tax information?

  8. #8
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    You'll need to parse the file. Since the assignment states you should use fscanf(), I suggest you give it a try. Then if you run into problems post your code and ask specific questions. It looks like you have the destination (field 3) and origin (field 1). In your data it looks like a value of 13 in these fields would indicate Georgia. Alabama looks to be 1.

    So the first line of actual information has people originally from Alabama going to Georgia. What the three last fields mean you will need to tell me, I don't know what the abbreviations mean.

    Jim

  9. #9
    young grasshopper jwroblewski44's Avatar
    Join Date
    May 2012
    Location
    Where the sidewalk ends
    Posts
    294
    As per the last three fields, I've been under the assumption that Tclausex properly translated the titles from abbreviations into real words. His post is above.

  10. #10
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    There are no extra char's in the file, that I can see. If you find any, handle them, and forget 'em.

    Status update?

  11. #11
    young grasshopper jwroblewski44's Avatar
    Join Date
    May 2012
    Location
    Where the sidewalk ends
    Posts
    294
    Oh sorry, I had some family things that took priority over this. I'll get back to the grind and keep you guys posted.

  12. #12
    young grasshopper jwroblewski44's Avatar
    Join Date
    May 2012
    Location
    Where the sidewalk ends
    Posts
    294
    Figured out how to get the numbers they were looking for. By comparing the correct number for Florida in their problem statement, I was able to determine that I only need to concern myself with the number of tax exemptions in regards to how many people.

  13. #13
    young grasshopper jwroblewski44's Avatar
    Join Date
    May 2012
    Location
    Where the sidewalk ends
    Posts
    294
    Is there a certain way to close the thread or mark as solved?

  14. #14
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    No. It will simply get pushed onto back pages, very quickly.

  15. #15
    young grasshopper jwroblewski44's Avatar
    Join Date
    May 2012
    Location
    Where the sidewalk ends
    Posts
    294
    It's a good thing I didn't close it, even if I could. I have another question: will you helpful souls check out my format string and data struct. It's my first time using either of these concepts in C and I'm having trouble understanding the formatting for fscanf. I was attempting to use this sample c - How to read specifically formatted data from a file? - Stack Overflow program to help form my formatting inside fscanf, but I'm reading out garbage. I was hoping ultimately someone could help me understand how to pull the different data types out of the stream, especially when quotes are surrounding the information.

    Here is my program so far. I'm just testing out my fscanf function at the time being (note: there are some artifacts floating around from me messing around, don't worry if I have unused variables.):

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include "record.h"
    
    #define MAXRECORDS    5000
    
    int main()
    {
        const char * readfile   = "stateoutflow.txt";
        const char * writefile  = "stateoutflow-report.txt";
        const char * read_mode    = "r";
        const char * write_mode = "w";
    
    
        FILE * datafile , * writeout;
    
    
        if( ( datafile = fopen( readfile , read_mode ) ) == NULL )
        {
            printf( "unable to open file \"%s\" with mode \"%s\"...quitting\n" , readfile , read_mode );
            return( 1 );
        }
    
    
        writeout = fopen( writefile , write_mode );
    
    
        OutflowRecord mainstorage;
    
    
        char charbuf[ 50 ];
        unsigned int n = 0;
    
    
        /* this while loop discards the first line of headers */
        while( ( fscanf( datafile , "%s" , charbuf ) == 1 ) && ( n++ < 9 ) )
            ;
    
    
        fscanf( datafile ,
                "\"%u\" "    // store:state code origin number
                "\"%*d\" "    // discard:county code origin number
                "\"%*d\" "    // discard:state code dest number
                "\"%*d\" "    // discard:county code dest number
                "\"*2c\" "    // discard:state abbreviation
                "\"%[^\"]\" "    // store:state name
                "%*d "        // discard:return number
                "%u "        // store:exemption number
                "%*d " ,    // discard:aggr_agi
                &mainstorage.st_origin_code , mainstorage.dest_state_name , &mainstorage.exmpt_num );
        printf( "State Code of Origin: %u\nName of Destination State: %s\nNumber of Exemptions: %u\n" , mainstorage.st_origin_code , mainstorage.dest_state_name , mainstorage.exmpt_num );
        fclose( datafile );
    
    
        return 0;
    }
    And record.h:
    Code:
    #define    MAXLEN    23
    
    
    typedef struct StateOutwardFlowRecords
    {
        unsigned int st_origin_code;
        char         dest_state_name[ MAXLEN ];
        unsigned int exmpt_num;
    } OutflowRecord;
    The file being used for reading is attached to the original post.
    Another bit of information; when I run the program, I get different results each time for the "State origin code".
    Last edited by jwroblewski44; 03-10-2013 at 11:12 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. interpreting fcnrl F_GETFL
    By MK27 in forum C Programming
    Replies: 8
    Last Post: 10-08-2008, 09:42 AM
  2. Help interpreting error message:
    By Karmachrome in forum C Programming
    Replies: 2
    Last Post: 12-11-2005, 04:13 AM
  3. including headers inside headers
    By kromozom in forum C++ Programming
    Replies: 5
    Last Post: 04-18-2005, 10:56 AM
  4. interpreting xml
    By WebmasterMattD in forum C++ Programming
    Replies: 3
    Last Post: 09-07-2003, 08:20 AM
  5. Interpreting characters from physical paper
    By Zewu in forum Tech Board
    Replies: 10
    Last Post: 12-31-2002, 03:53 AM