Guys,
I was going thru a tutorial in C which asked me to
1. declare a fn in the header file
2. define the fn in c file
3. write another file with main and use the function defined in (2)
Now if i compile lab6.c with MSDEV, i get the following error.
I am able to guess it should be with the library.
In that case we need to check the linking part.
Can someone tell me how to get this working?
I was going thru a tutorial in C which asked me to
1. declare a fn in the header file
2. define the fn in c file
3. write another file with main and use the function defined in (2)
Code:
[SIZE="2"]
/* [B]employee.h[/B] */
/* addEmployee reads each field from standard
* input into the next available Employee slot,
* as in the exercise in the previous section.
* It returns the index of the Employee
* just added, or -1 if the array is full */
int addEmployee(void);
/* printEmployee also returns the index of the
* Employee just printed, or -1 if the index i
* is invalid */
int printEmployee(int i);
/* Does what it says: */
int numEmployees(void);[/SIZE]
Code:
[SIZE="2"]/* [B]employee.c [/B]*/
#include "employee.h"
#include <stdio.h>
#include <string.h>
#define MAXEMPS 5
struct Employee {
char last[16];
char first[11];
char title[16];
int salary;
};
static struct Employee emps[MAXEMPS];
static int nemps = 0;
int addEmployee(void) {
if (nemps == MAXEMPS)
return -1;
printf("Enter last: "); fflush(stdout);
gets(emps[nemps].last);
if (strlen(emps[nemps].last) == 0)
return -1;
printf("Enter first: "); fflush(stdout);
gets(emps[nemps].first);
printf("Enter title: "); fflush(stdout);
gets(emps[nemps].title);
printf("Enter salary: "); fflush(stdout);
scanf("%d", &emps[nemps].salary);
getchar(); /* eat newline */
return nemps++;
}
int printEmployee(int i) {
if (i < 0 || i >= nemps)
return -1;
printf("{%s,%s,%s,%d}",
emps[i].last,
emps[i].first,
emps[i].title,
emps[i].salary);
return i;
}
int numEmployees(void) {
return nemps;
}[/SIZE]
Code:
[SIZE="2"]/* [B]lab6.c[/B] */
#include "employee.h"
#include <stdio.h>
int main() {
int i;
/* Fill Employee array: */
while (addEmployee() != -1)
;
/* Print each Employee: */
for (i = 0; i < numEmployees(); ++i) {
printEmployee(i);
putchar('\n');
}
return 0;
}[/SIZE]
Now if i compile lab6.c with MSDEV, i get the following error.
ttest.obj : error LNK2001: unresolved external symbol _age
Debug/ttest.exe : fatal error LNK1120: 1 unresolved externals
I am able to guess it should be with the library.
In that case we need to check the linking part.
Can someone tell me how to get this working?