hit a wall

This is a discussion on hit a wall within the C Programming forums, part of the General Programming Boards category; I am writing a program that is supposed to read info from a file clock.txt that has the number of ...

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    14

    Question hit a wall

    I am writing a program that is supposed to read info from a file clock.txt that has the number of employees then a name and then payrate and then another name and payrate. I have a struct

    Code:
    struct employee {
           char* first[MAX_LEN];
           char* last [MAX_LEN];
           double payperhr;
           double taxes;
           double hours_in_week;
                    };
    the information im suppose to read in is
    2
    john slacker 5.15
    jane worker 10

    now i have

    Code:
    void scanclock(struct employee a){
         
       int i;
       int week, employee_day;
       double minin,hrin;
       double minout,hrout;
       int num_employee;
       FILE* fp;
        
     fp = fopen("clock.txt", "r");
     
     fscanf(fp, "%d", num_employee);
     
     for(i=0; i<=num_employee; i++)
        {
     fscanf(fp, "%s%s%d", &a.first[i], &a.last[i], &a.payperhr);
     
        }
     fscanf(fp, "%d", &week);
     
     for(i=1; i<=week; i++)
        {
          fscanf(fp, "%d", &employee_day);
          fscanf(fp, "lf%lf%lf%lf", &minin, &hrin, &minout, &hrout); 
        }
        
    fclose(fp);
    I wanted to see if this either looks ok... and does it seem like im going down the right path? a.payperhr does that need to be strcpy and.... and should i keep it in a function or possibly better to do this in int main?

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    It's always good to do things in functions.
    The parameter struct employee a should be struct employee *a since it represents an array of employee structs.
    Your first for loop condition should be i < num_employee, otherwise it will read once more than you want.
    Your second fscanf format should be "%s%s%lf" since payperhr is a double not an int.
    As for the other data you're reading, you haven't shown that in the data you posted.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  3. #3
    Registered User
    Join Date
    Apr 2012
    Posts
    14
    ahh ok thanks.. does any one know what would the basic format of sending a structure though a fucntion be? kinda as in the case above but not really important more for just trying to see another example.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Camera (Wall Alpha-ing)
    By JohnLeeroy in forum Game Programming
    Replies: 3
    Last Post: 04-05-2011, 03:07 PM
  2. gcc -Wall -pedantic
    By flexo87 in forum C Programming
    Replies: 5
    Last Post: 01-26-2009, 02:04 PM
  3. Hit a brick wall here...
    By jwillisoa in forum C Programming
    Replies: 2
    Last Post: 07-15-2007, 10:14 PM
  4. The wall behind is showing over the wall in front. (Glut)
    By Queatrix in forum C++ Programming
    Replies: 2
    Last Post: 10-22-2005, 05:50 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21