Thread: strange errors?

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    34

    strange errors?

    i am wrote a fuction and when i test it, i get these strange errors that i dont know how to fix...any help would be appreciated... Thanx

    inside main...
    Code:
    myBoolean y;
    
    y= CmpEmployee(struct personal employee[0],struct personal employee[0]);
    if ( y )
    	printf("Employees Do Not Match");
    else printf("Employees are the same");
    
    y= CmpEmployee(struct personal employee[2],struct personal employee[0]);
    if ( y )
    	printf("Employees Do Not Match");
    else printf("Employees are the same");
    function...
    Code:
    myBoolean CmpEmployee(struct personal emp1[],struct personal emp2[])
    {
    myBoolean cmp = eTrue;
      if( emp1->ID_Number != emp2->ID_Number)
    {
       cmp = eFalse;
       return (cmp);
    }
    else
      if( myStrCmp (emp1->F_name, emp2->F_name) != 0)
    {
      cmp = eFalse;
      return (cmp);
    }
    else
      if( myStrCmp (emp1->L_name, emp2->L_name) != 0)
    {
      cmp = eFalse;
      return (cmp);
    }
    else
      if( emp1->gender != emp2->gender)
    {
      cmp = eFalse;
      return (cmp);
    }
    else
      if( emp1->birth.Birth_month == emp2->birth.Birth_month)
    {
      cmp = eFalse;
      return (cmp);
    }
    else
      if( emp1->birth.Birth_day == emp2->birth.Birth_day)
    {
      cmp = eFalse;
      return (cmp);
    }
    else
      if( emp1->birth.Birth_year == emp2->birth.Birth_year)
    {
      cmp = eFalse;
      return (cmp);
    }
    else
      if( myStrCmp (emp1->stuff.street, emp2->stuff.street) != 0)
    {
      cmp = eFalse;
      return (cmp);
    }
    else
      if( myStrCmp (emp1->stuff.city, emp2->stuff.city) != 0)
    {
      cmp = eFalse;
      return (cmp);
    }
    else
      if( myStrCmp (emp1->stuff.state, emp2->stuff.state) != 0)
    {
      cmp = eFalse;
      return (cmp);
    }
    else
      if( myStrCmp (emp1->stuff.zip, emp2->stuff.zip) != 0)
    {
      cmp = eFalse;
      return (cmp);
    }
    return (cmp);
    }

    errors...
    Code:
    Database\Employee.c(116) : error C2143: syntax error : missing ')' before 'type'
    
    Database\Employee.c(116) : error C2198: 'CmpEmployee' : too few actual parameters
    
    Database\Employee.c(116) : error C2059: syntax error : ')'
    
    Database\Employee.c(121) : error C2143: syntax error : missing ')' before 'type'
    
    Database\Employee.c(121) : error C2198: 'CmpEmployee' : too few actual parameters
    
    Database\Employee.c(121) : error C2059: syntax error : ')'
    Error executing cl.exe.
    
    Employee.obj - 6 error(s), 0 warning(s)

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    The numbers in parentheses are the line numbers in the file in which the error occurs. You'll notice from reading the messages that you are simply missing a closing parentheses on lines 116 and line 121. It should be easy to spot.

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Holy guacamole. Why don't you just leave all those return's out except the very last one? The rest are unnecessary.
    Last edited by itsme86; 12-21-2004 at 04:28 PM.
    If you understand what you're doing, you're not learning anything.

  4. #4
    Registered User
    Join Date
    Oct 2004
    Posts
    34
    I know how to use the compiler....

    the specific lines to the errors are
    line 116...
    Code:
     
    y= CmpEmployee(struct personal employee[0],struct personal employee[0]);
    and line 121...
    Code:
    y= CmpEmployee(struct personal employee[2],struct personal employee[0]);
    i just dont know where the missing ' )' before 'type' or syntax error is...
    sorry bout the confusion.

  5. #5
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    You can't create a struct instance while calling functions like that. You create them before you call the function. It should work more like this:
    Code:
    {
      struct foo yay[5];
      int y;
    
      y = compare(yay[0], yay[1]);
    }
    And then the receiving function doesn't need to accept them as an array...drop the []'s there.

    It's the same thing as trying to do it with an int:
    Code:
    {
      int a;
    
      go_my_func(int a);
    }
    You don't do that, do you? No, you just put the name of the variable. You don't include the type there.
    Last edited by itsme86; 12-21-2004 at 05:32 PM.
    If you understand what you're doing, you're not learning anything.

  6. #6
    Registered User
    Join Date
    Oct 2004
    Posts
    34
    Code:
    typedef enum{
    	eFalse = 0,
       eTrue  = 1,}
    	myBoolean;

  7. #7
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    I made your code a tad bit better from my prespective. The CmpEmployee function needed to trim down on those else's. Also the myStrCmp could be easily replaced with strcmp.
    Code:
    cmp = eFalse;
    return (cmp);
    Could be easily trimmed down to:
    Code:
    return eFalse;
    I also thought the
    Code:
    typedef enum{
       eFalse = 0,
       eTrue  = 1
    } myBoolean;
    Was an overkill if you just want TRUE & FALSE you could add these to the top of your file:
    Code:
    #define TRUE 1
    #define FALSE 0
    And
    Code:
    y= CmpEmployee(struct personal employee[2],struct personal employee[0]);
    should be replaced with:
    Code:
    y= CmpEmployee(employee[2], employee[0]);
    Though of course you'd have to create the arrays that create employee[0] and employee[2]. Here's another version for you to use as a creative reference:
    Code:
    #include <stdlib.h>
    #include <stdio.h>
    
    #define FALSE 0
    #define TRUE 1
    #define MALE 1;
    #define FEMALE 2;
    
    /// STRUCTURES
    struct Sbirth {
    	double Birth_year;
    	double Birth_month;
    	double Birth_day;
    };
    
    struct Sstuff {
    	char street[50];
    	char city[50];
    	char state[15];
    	char zip[10];
    };
    
    struct personal {
    	char F_name[50];
    	char L_name[50];
    	double salary;
    	int gender;
    	int ID_Number;
    	struct Sbirth birth;
    	struct Sstuff stuff;
    };
    
    int CmpEmployee(struct personal emp1,struct personal emp2);
    
    /// MAIN
    int main() {
    	int cmp;
    
    	struct personal Employee1;
    	Employee1.ID_Number = 1;
    	strcpy(Employee1.F_name, "Kleid");
    	strcpy(Employee1.L_name, "Wilson");
    	Employee1.salary = 200;
    	Employee1.gender = MALE;
    	Employee1.birth.Birth_year = 1987;
    	Employee1.birth.Birth_month = 7;
    	Employee1.birth.Birth_day = 8;
    	strcpy(Employee1.stuff.zip, "3434");
    	strcpy(Employee1.stuff.state, "OR");
    	strcpy(Employee1.stuff.city, "Portland");
    	strcpy(Employee1.stuff.street, "Miracle Street");
    	
    	struct personal Employee2;
    	Employee2.ID_Number = 2;
    	strcpy(Employee2.F_name, "Jesus");
    	strcpy(Employee2.L_name, "Christ");
    	Employee2.salary = 2;
    	Employee2.gender = MALE;
    	Employee2.birth.Birth_year = 1;
    	Employee2.birth.Birth_month = 12;
    	Employee2.birth.Birth_day = 25;
    	strcpy(Employee2.stuff.zip, "37322");
    	strcpy(Employee2.stuff.state, "ISLAM");
    	strcpy(Employee2.stuff.city, "Jerusalem");
    	strcpy(Employee2.stuff.street, "Jerusalem dr.");
    	
    	struct personal Employee3;
    	Employee3.ID_Number = 1;
    	strcpy(Employee3.F_name, "Kleid");
    	strcpy(Employee3.L_name, "Wilson");
    	Employee3.salary = 200;
    	Employee3.gender = MALE;
    	Employee3.birth.Birth_year = 1987;
    	Employee3.birth.Birth_month = 7;
    	Employee3.birth.Birth_day = 8;
    	strcpy(Employee3.stuff.zip, "3434");
    	strcpy(Employee3.stuff.state, "OR");
    	strcpy(Employee3.stuff.city, "Portland");
    	strcpy(Employee3.stuff.street, "Miracle Street");
    	
    	if(CmpEmployee(Employee1, Employee2))
    		printf("%s & %s are the same!\n", Employee1.F_name, Employee2.F_name);
    	else
    		printf("%s & %s are different!\n", Employee1.F_name, Employee2.F_name);
    		
    	if(CmpEmployee(Employee1, Employee3))
    		printf("%s & %s are the same!\n", Employee1.F_name, Employee3.F_name);
    	else
    		printf("%s & %s are different!\n", Employee1.F_name, Employee3.F_name);
    		
    	return 0;
    }
    
    // Return true if they are identical employees
    int CmpEmployee(struct personal emp1,struct personal emp2) {
    	
    	double const nEmployee1[] = {
    		emp1.ID_Number,
    		emp1.gender,
    		emp1.birth.Birth_month,
    		emp1.birth.Birth_day,
    		emp1.birth.Birth_year
    	};
    	
    	char const *szEmployee1[] = {
    		emp1.F_name,
    		emp1.L_name,
    		emp1.stuff.street,
    		emp1.stuff.city,
    		emp1.stuff.state,
    		emp1.stuff.zip
    	};
    	
    	double const nEmployee2[] = {
    		emp2.ID_Number,
    		emp2.gender,
    		emp2.birth.Birth_month,
    		emp2.birth.Birth_day,
    		emp2.birth.Birth_year
    	};
    	
    	char const *szEmployee2[] = {
    		emp2.F_name,
    		emp2.L_name,
    		emp2.stuff.street,
    		emp2.stuff.city,
    		emp2.stuff.state,
    		emp2.stuff.zip
    	};
    	
    	int i;
    	// Compare numerical data:
    	for(i=0; i<5; i++) {
    		if(nEmployee1[i] != nEmployee2[i])
    			return FALSE;
    	}
    	
    	// Compare string data:
    	for(i=0; i<6; i++) {
    		if(strcmp(szEmployee1[i], szEmployee2[i]))	// If the strings are the same
    			return FALSE;	// Then the employees aren't the same! 
    	}
    	
    	return TRUE;
    }
    I hope this helps you :)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sneaky little linker errors...
    By Tozar in forum C++ Programming
    Replies: 8
    Last Post: 10-25-2006, 05:40 AM
  2. Errors with header files in OpenGL using VisualC++
    By wile_spice in forum Game Programming
    Replies: 3
    Last Post: 06-22-2006, 08:56 AM
  3. strange errors
    By duvernais28 in forum C Programming
    Replies: 9
    Last Post: 02-19-2005, 09:40 AM
  4. help with strange errors
    By rockdj in forum C++ Programming
    Replies: 4
    Last Post: 07-27-2004, 11:42 AM
  5. executing errors
    By s0ul2squeeze in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2002, 01:43 PM