Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

What the FUCK

Name: Anonymous 2009-11-25 21:00

I keep getting "in main, syntax error before employee"
I've tried every conceivable solution, what the FUCK am I doing wrong?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define empmax  20
#define MAX_LEN 30
#define regtax  .10
#define overtax .20

struct employee{
  char first[MAX_LEN];
  char last[MAX_LEN];
  double payperhr;
  double gross;
  double taxes;
  double hours_in_week;
};

typedef struct employee employee;

void getclock(employee *array);
FILE *gfopen(char name[], char mode[]);

int main(){
   
   
    employee array[empmax];
   
    getclock(struct employee *array);
   
    system("pause");
   
    return 0;
}

void getclock(employee *array){
     char tempfirst[MAX_LEN], templast[MAX_LEN];
     int i, j, k, l, empnum, numweeks, numshifts;
     double timeinhr, timeinmin, timeouthr, timeoutmin, timeinshift, overhours, taxpayed, grossearned, netpay;
     FILE *input;
    
     input = gfopen("clock.txt", "r");
    
     fscanf(input, "%d", empnum);
     for(i=0; i<empnum; i++){
              fscanf(input, "%s %s %d", array[i].first, array[i].last, &array[i].payperhr);
              }
             
     //Scans number of weeks on file, goes through each week
     fscanf(input, "%d", &numweeks);
     for(i=0; i<numweeks; i++){
             
              //Scans for number of shifts in each week
              fscanf(input, "%d", &numshifts);
             
              //Goes through each shift
              for(j=0;j<numshifts;j++){
              fscanf(input, "%s %s", tempfirst, templast);
             
              //Finds out who the shift belongs to
              for(k=0;k<empnum;k++){
              //Adds all the hours in the shifts belonging to each person
              if(strcmp(array[k].first, tempfirst)==0 && strcmp(array[k].last, templast)==0){
              fscanf(input, "%lf %lf %lf %lf", &timeinhr, timeinmin, timeouthr, timeinmin);
                            timeinmin=timeinmin/60;
                            timeoutmin=timeoutmin/60;
                            timeinshift=(timeouthr+timeoutmin)-(timeinhr+timeinmin);
                            array[k].hours_in_week=array[k].hours_in_week+timeinshift;
                            }//Closes if statement
                            }//Closes shift ownership loop
                            }//Closes shift loop
                           
                            //Takes the hours worked in week for each person and calculates earnings and taxes
                            for(l=0;l<empnum;l++){
                            //Determines if hour worked for the person is over 40
                            if(array[l].hours_in_week>40){
                            overhours=array[l].hours_in_week-40;
                            grossearned=(overhours*array[l].payperhr*1.5)+(40*array[l].payperhr);
                            taxpayed=(overhours*array[l].payperhr*1.5)*.20+(40*array[l].payperhr)*.10;
                            array[l].gross=array[l].gross+grossearned;
                            array[l].taxes=array[l].taxes+taxpayed;
                            }
                           
                            else if(array[l].hours_in_week<41){
                            grossearned=array[l].payperhr*array[l].hours_in_week;
                            taxpayed=grossearned*.10;
                            }
                           
                            //Resets weekly hour counter
                            array[l].hours_in_week=0;
                           
                            }//Closes earnings and taxes calculation loop
                            }//Closes number of shifts counter
                            }//Closes weeks loop

                           
                           
//File open function
FILE *gfopen(char name[], char mode[]){
     FILE *input;
     input = fopen(name, mode);
     if(input == NULL)
     {
              printf("Error opening file %s, aborting.\n", name);
              exit(1);
              }
     return input;
}

Name: Anonymous 2009-11-25 21:18

1. Don't "typedef struct this this" because the compiler won't know whether "this" refers to the actual struct name or the typedef alias.  This "struct this" can be interpreted as "struct struct this" because "this" is already aliased to "struct this".
2. Apparently it confuses you as well as the compiler because on this line:
   getclock(struct employee *array);
you still somehow feel the need to explicity call employee a struct, and then call it as if it were the prototype, or something.

Anyways, only like the first 30-40 lines need to be changed.

Here, I fixed your immense fail for you:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define empmax  20
#define MAX_LEN 30
#define regtax  .10
#define overtax .20

typedef struct employee {
  char first[MAX_LEN];
  char last[MAX_LEN];
  double payperhr;
  double gross;
  double taxes;
  double hours_in_week;
} employee_t;


void getclock(employee_t *array);
FILE *gfopen(char name[], char mode[]);

int main(){
  
  
    employee_t array[empmax];
  
    getclock(array);
  
    system("pause");
  
    return 0;
}

void getclock(employee_t *array){



That will be $20.

Name: stupid typos 2009-11-25 21:21

>>2
s/This "struct this"/Thus "struct this"

you still somehow feel the need to explicity call employee a struct, and then call it as if it were the prototype, or something.
I should rephrase this: You still somehow feel the need to use "struct employee" instead of just the "employee" alias (or perhaps you were just trying everything since you had no idea wtf was its problem), and then call getclock() with some confusing syntax that looks like its prototype rather than passing a pointer to an array.

Name: Anonymous 2009-11-25 21:24

Yea, in the midst of trying everything I could I ended up fucking some shit up.

The reason I typedef'd to begin with was because the compiler was still telling me I had syntax errors before struct, in my main, when I called the getclock function.

Anyway, I'll try what you wrote and see what happens.

Name: Anonymous 2009-11-25 21:28

It worked fine for me.  Although I didn't actually test-run the program to make sure that it does what it's intended to (which I wasn't even thinking about), but it compiled fine and the errors were so obvious that everything should still work fine if your original program logic is OK.

Name: Anonymous 2009-11-25 21:30

"syntax error before employee_t"

Well FUCK.

Name: Anonymous 2009-11-25 21:30

getclock(struct employee *array);
WTF are you doing? Don't give the type, just getclock(array);.

Name: Anonymous 2009-11-25 21:31

I'm using DevCpp, could it be the compiler giving me shit for no good reason? Also, the program is incomplete, but I fixed all the other compile errors except for this little fiasco.

Name: Anonymous 2009-11-25 21:31

>>6
Really?  What compiler/version are you using and what compiler flags?

Name: Anonymous 2009-11-25 21:34

>>8
Is this the entire program?  And what line of the program are you now getting the error in?  I am using Dev-CPP too and it compiles without a hitch for me.

Name: Anonymous 2009-11-25 21:36

>>2-3
Don't "typedef struct this this" because the compiler won't know whether "this" refers to the actual struct name or the typedef alias.

"this" refers to the typedef, which refers to the struct.
"struct this" refers to the struct, obviously.
I don't know what the fuck else you might be thinking of, or your wrong bitch.

Name: Anonymous 2009-11-25 21:42

Dev-cpp is software from a past era. Get emacs+gcc or Visual Studio Express, depending on your sexual orientation.

Name: Anonymous 2009-11-25 21:48

>>2
1. Don't "typedef struct this this" because the compiler won't know whether "this" refers to the actual struct name or the typedef alias.  This "struct this" can be interpreted as "struct struct this" because "this" is already aliased to "struct this".
Don't listen to anon, he knows not what he says. You can't typedef a struct without including the struct keyword inside the typedef, so 'struct something' can never refer to a typedef, it's a real struct. There is no ambiguity there.

Good form however is like this:

struct employee_s {
  // shit
};
typedef struct employee_s employee_t;


Don't use 'employee' at all (not even for the struct in case of sepples); this way someone can use it as a variable name.

Name: Anonymous 2009-11-25 23:20

>>13
Better form is to use a capital for type names.
struct Employee_s {
  // shit
};
typedef struct Employee_s Employee;


And then you can do Employee employee; all you want. Conventions like employee_s, employee_t, employee_m are ugly as shit, if you're not a GNU fag, hide them!

Name: Anonymous 2009-11-26 0:58

>>14
Javafag

Name: Anonymous 2009-11-26 3:01

ITT: /prog/ forgets that the following is valid
#include <string>
using namespace std;
int main()
{
    string string = "a";
    string.at(0); //wouldn't compile if string weren't the variable
    return 0;
}

Name: Anonymous 2009-11-26 3:26

>>16
This is C.  Take your Sepples bullshit to a relevant thread.

Name: Anonymous 2009-11-26 3:57

>>16
Jesus fuck a language where classes are not objects?

Name: Anonymous 2009-11-26 6:53

>>16
I was about to say "Fucks up the highlighting in all IDEs", but then I checked and emacs takes it like a man. Fucking king of editors.

Someone check with vim.

Name: Anonymous 2009-11-26 12:20

>>19
VC++ Express 2008 doesn't highlight class types nor variables with default settings. However, if you change the identifier color, it simply makes both the type and the variable that color.

Name: Anonymous 2009-11-26 13:58

>>19
Vim neither highlights string nor string with the default settings and syntax files.

Name: Anonymous 2009-11-26 16:58

>>17
apologies
typedef struct {} thing;
      
int main()
{
    thing thing;
    return 0;
}

Name: Anonymous 2009-11-26 20:19

>>19
IF IF = THEN THEN THEN = ELSE; ELSE ELSE = IF;

Name: Anonymous 2010-12-09 14:23

Name: Anonymous 2011-02-03 1:42

Name: Anonymous 2011-02-03 4:04

Don't change these.
Name: Email:
Entire Thread Thread List