Help with error: undefined reference to (function I defined)
Hello,
I am new to C programming (taking it as a class) and this forum. I have read homework policy. I've done most of the work for my current assignment but I am stuck with a error that won't go away. I've tried several fixes myself but nothing fixes it. I wrote it without the function and it worked perfectly, then inserted the function 'payroll()', moved the sprintf() line (which works) into it. Can someone tell me what I'm doing wrong? (I need a quick response.)
-------------------------------------
The assignment states:
"Write a C program that accepts as input from the keyboard a floating
point number, an integer, and a character. Each of these inputs should be
preceded by a prompt and stored using individual variable names.
Have your program call a function that assembles the input data into a single
string. Display the assembled string using the puts() call back in main after
the function has completed. "
--------------------------------------
The error refers to the line where I call the function payroll() and pass the variables to it. I'm using C-Free Standard for my compiler and the error is this:
[Error] C:\Program Files\C-Free Standard\temp\Untitled4.cpp:28: undefined reference to `payroll(int, char, float, char)'.
--------------------------------------
My code is below:
Code:
#include <stdio.h> /*include standard input/output library*/
#include <string.h> /*include string library*/
#define NSIZE 21 /*define the max name size*/
char name [NSIZE]={0}; /*declare character string variable name */
int empID; /*declare integer variable empID*/
float hours; /*declare float variable hours*/
char timeCard [51]={0}; /*declare character string variable timeCard */
char payroll(int, char, float, char); /*function prototype for payroll()*/
int main() /*call main()*/
{ /*begin main()*/
printf("Enter employee's id number: "); /*prompt user for id input*/
scanf("%d", &empID); /*get empID from keyboard*/
printf("\nEnter employee's name (LAST,First) with no spaces): "); /*prompt user for name input*/
scanf("%s", name); /*get empID from keyboard*/
printf("\nEnter hours: "); /*prompt user for hours input*/
scanf("%f", &hours); /*get hours from keyboard*/
payroll (empID, name[NSIZE], hours, timeCard [51]); /* call function*/
printf("\n\nTime card entry is:"); /*line to inform user */
puts(timeCard); /*use display string timeCard compiled in payroll() */
printf("\n\n"); /* line breaks (x3) */
return 0; /* return control */
} /* end main */
char payroll (int empID, char name[NSIZE], float hours, char timeCard [51] ) /*function header for payroll()*/
{ /* begin payroll() */
sprintf(timeCard, "%d/%s/%4.2f hrs", empID, name, hours); /* all variables printed into timeCard string */
return (timeCard [51]); /*order function payroll() to return the string timeCard to calling function*/
} /*end payroll()*/