Thread: C in UNIX environment; external bubble sort doesn't work

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    2

    C in UNIX environment; external bubble sort doesn't work

    Code:
    void BubbleSort(EmployeeRecord employees[], int max_employee); //3.12
    
    void BubbleSort(EmployeeRecord employees[], int max_employee) //3.12
    {
    	int o, i;
    
    	for (o = 0; o < MAX_EMPLOYEE; o++)
    	{
    		for (i =0; i < MAX_EMPLOYEE - 1; i++)
    		{ 
    			if (strcmp(employees[i].lastname,employees[i+1].lastname)>0)
    			{
    				EmployeeRecord tempRec = employees[i];
    				employees[i] = employees[i+1];
    				employees[i+1] = tempRec;
    			}
    		}
    	}
    }
    I'm trying to make an external bubble sort that will sort a record of employees. All of that above is my external bubble sort function. I'm still not quite used to using Linux, but I'm using PuTTY to connect to my school's Linux servers and using Pico/GNU nano 1.3.8 to write this. When I gcc it, I get the following errors:

    sort.c:1: error: expected â)â before âemployeesâ
    sort.c:3: error: expected â)â before âemployeesâ
    make: *** [sort.o] Error 1
    I just can't figure out why I'm getting that error. When I put the function back into the main source file, the sort works fine. As an external function, however, it doesn't work. What did I miss here?

    Here's my main source file up until int main(void):

    EDIT: "float ........itax" should read "*s_s_itax" without the underscores. I'm guessing a censor is filtering it out.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    #define FEDTAXRATE 0.15
    #define STATETAXRATE 0.07
    #define SSITAXRATE 0.0775
    #define OVERTIME 40
    #define FORMAT1 "  %-25s   %5.2f      %7.2f     %7.2f    %7.2f    %6.2f     %7.2f\n"
    #define FORMAT2 "                                         %7.2f                %7.2f    %6.2f\n\n"
    #define MAX_EMPLOYEE 5
    
    typedef struct EmployeeRecord
    {
    	char lastname[20+1];
        char firstname[20+1];
    	float payrate;
    	float hours;
    	float defr;
    	float net;
    	float reg_hours; 
    	float ovt_hours;
    	float gross;
    	float ft, st, ssit;
    } EmployeeRecord;
    
    void PrintReportHeadings(FILE * report); //3.1
    void InitializeAccumulators(float *tot_payrate,
    							float *tot_reghours,
    							float *tot_ovthours, 
    							float *tot_gross,
    							float *tot_fed,
    							float *tot_state,
    							float *tot_SSI,
    							float *tot_defr,
    							float *tot_net); //3.2
    void InputWorkerData(char *lastname,
    					 char *firstname,
    					 float *hours,
    					 float *payrate,
    					 float *defr); //3.3 
    float CalcGross (float hours,
    				 float payrate); //3.4
    void CalcTaxes(float gross,
    			   float defr,
    			   float *fedtax,
    			   float *statetax,
    			   float ........itax);	//3.5
    float CalcFedTax(float gross,
    				 float deferred); //3.5.1
    float Calcstatetax(float fedtax); //3.5.2
    float CalcSSITax(float gross,
    				 float deferred); //3.5.3
    void AddDetailToAccumulators(float *tot_payrate,
    							 float *tot_reghours,
    							 float *tot_ovthours, 
    							 float *tot_gross,
    							 float *tot_fed, 
    							 float *tot_state,
    							 float *tot_SSI,
    							 float *tot_defr,
    							 float *tot_net,
    							 float *fedtax,
    							 float *statetax,
    							 float ........it,
    							 float gross,
    							 float reg_hours,
    							 float ovt_hours,
    							 float payrate,
    							 float defr); //3.6
    extern float CalcNetPay(float gross,
    				 float *fedtax,
    				 float *statetax,
    				 float ........itax,
    				 float defr); //3.7
    void CalcAverages(float *tot_payrate, 
    				  float *tot_reghours, 
    				  float *tot_ovthours, 
    				  float *tot_gross,
    				  float *tot_fed,
    				  float *tot_state,
    				  float *tot_SSI,
    				  float *tot_defr,
    				  float *tot_net,
    				  FILE * report); //3.8
    void PrintTotAvg(float *tot_payrate,
    				 float *tot_reghours,
    				 float *tot_ovthours, 
    				 float *tot_gross,
    				 float *tot_fed,
    				 float *tot_state,
    				 float *tot_SSI,
    				 float *tot_defr,
    				 float *tot_net,
    				 float avg_payrate,
    				 float avg_reghours,
    				 float avg_ovthours,
    				 float avg_gross,
    				 float avg_fed,
    				 float avg_state,
    				 float avg_SSI,
    				 float avg_defr,
    				 float avg_net,
    				 FILE * report); //3.9
    void CalcHours(float *hours, 
    				float *reg_hours, 
    				float *ovt_hours); // 3.10
    void PrintEmployeeData(EmployeeRecord employees[],
    					   int count_emp,
    					   FILE * report); //3.11
    extern void BubbleSort(EmployeeRecord employees[], int max_employee); //3.12
    Last edited by stn0091; 05-13-2009 at 02:30 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    You're missing the struct, and some #defines.

    Since they need to be in both files, look into how to create a header file which both #include
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    2
    Thank you. I did as you suggested and it runs fine now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. bubble sort help.
    By zeromx in forum C Programming
    Replies: 9
    Last Post: 10-30-2006, 07:37 AM
  2. Array/Structure Bubble Sort
    By JKI in forum C++ Programming
    Replies: 3
    Last Post: 09-29-2003, 11:59 AM
  3. debug to release modes
    By DavidP in forum Game Programming
    Replies: 5
    Last Post: 03-20-2003, 03:01 PM
  4. Unresolved external symbols in OGL
    By Shadow12345 in forum Game Programming
    Replies: 4
    Last Post: 08-04-2002, 09:46 PM
  5. the bubble sort doesn't work help
    By Matt in forum C Programming
    Replies: 2
    Last Post: 12-13-2001, 06:14 PM