A "char" is one character. I.e., 'a' or 'b' or 'c' or ';'
A character array is the same thing as a string. It's an array of characters.
A pointer to a character is almost the same thing as a character array.
When you have an array. array[1] just means go to the memory address of array[0] and go to the memory address 1 <unit (int/char/etc)> ahead of that. So a pointer just means it points to a memory address. Thus if you have a pointer, you could do pointer[1] and it'd work fine.
In fact, when you pass an array as an argument, it is technically "decayed" to a pointer. There are a few differences between an array and a pointer (like what sizeof returns, or what you get when you type in the variable with no index).
As for your error, the latest one you posted is the "correct" error, or rather the one I got, and the one I expected. Also, I removed the link because it had a few C++ specific things, although the concept remains the same. Just didn't really want to explain what "cout" or "new" or "delete" was.
First of all, when you call a function, do not put the argument as timeCard[51]. Just use timeCard. If you use timeCard[51], it thinks you're giving it the 51st character of timeCard. The function declaration knows it's of length 51. If you pass timeCard[51] thats a char not a char[], thus the compiler will give you a warning.
Second of all, fix your variables (they should not be global!). This isn't an error, it's just bad technique.
Notice how I changed your function prototype to character arrays instead of characters. If you are unsure of what to use for your function prototype, you can just copy and paste the function declaration and add a semicolon. For example:
Code:
char payroll (int empID, char name[NSIZE], float hours, char timeCard[51] );
is a valid function prototype!
This seems to be valid code.
Code:
#include <stdio.h>
#include <string.h>
#define NSIZE 21
char payroll(int, char[], float, char[]);
int main()
{
char name[NSIZE];
int empID;
float hours;
char timeCard[51];
printf("Enter employee's id number: ");
scanf("%d", &empID);
printf("\nEnter employee's name (LAST,First) with no spaces): ");
scanf("%s", name);
printf("\nEnter hours: ");
scanf("%f", &hours);
payroll (empID, name, hours, timeCard);
printf("\n\nTime card entry is: ");
puts(timeCard);
printf("\n\n");
return 0;
}
char payroll (int empID, char name[NSIZE], float hours, char timeCard[51] )
{
sprintf(timeCard, "%d/%s/%4.2f hrs", empID, name, hours);
return (timeCard[51]);
}