OK, let's go over function declarations, function calls and function definitions. The summary of all this will be that they have to match.
Your declaration is this:
Code:
int get_input (char, contact);
This says you are passing, by value, a single one byte characters, and a contact datatype (whatever that is - it doesn't really matter).
For function call is this:
Code:
get_input (prompt1, &input_ptr->name);
So, at run time, you will pass a copy of prompt1, which is the address of a char[25] array, and the address of the name field of the structure pointed to by input_ptr.
You've scored 0 for 2 so far.
Now, your function definition says this:
Code:
int get_input (prompt, *input_ptr)
Not even close. You have to supply a data type for both parms, and you haven't specified a data type for either.
3 strikes - you are out. (Actually, more bugs than that - but I won't dwell on something you don't understand with too critical an eye.)
Now, Going back to my first point that the function declaration, function call and function definition have to match. You need to decide if you want pass parms by value or by reference. Here's an example of the differences between the two.
Call by value: You tell the compiler to make a copy (essentially) of whatever variable you want to pass to a function. The compiler (well, it's not actually the "compiler", but the code generated BY the compiler - but I'll call it the compiler for discussion purposes) will make a copy of the "value" and place it on the stack. When the function gets control, it uses the copy of the value and cannot touch the original value. Here's a commented example:
Code:
#include <stdio.h>
int myfunc(char) ; // function declaration
int main() {
char mychar = 'Z' ;
int rc ; // return code
// mychar will be Z
printf("main: before myfunc() call, mychar = %c\n", mychar) ;
// Call myfunc(), using a call be value syntax. A copy of the
// actual value of mychar will be placed on the stack. myfunc() will
// never have access to the original mychar variable.
rc = myfunc(mychar) ; // function call
// Print out the value of mychar. It will still be Z, because
// function myfunc() changed the copy of mychar that was placed
// on the stack. This now proves that function myfunc() did not
// use the original value of mychar - it only changed a temporary
// copy of it that was on the stack.
printf("main: after myfunc() call, mychar = %c\n", mychar) ;
return 0 ;
}
int myfunc(char xxx) { // function definition
// report the incoming value.
printf("xxx should be Z, and it is: %c \n", xxx ) ;
// Change variable xxx to a new value.
xxx = 'H' ;
// This shows that the value was changed.
printf("xxx should be H, and it is: %c \n", xxx) ;
return 0 ;
}
Maybe the most important thing to point out from the above example is that the function myfunc() cannot change the calling routine's variable in a call-by-value scenario.
Call by reference: Let's change our example just a little now to a call-by-reference call. We need to use a pointer variable and change our function declaration, call and definition. The primary differences are in red.
Code:
#include <stdio.h>
int myfunc(char *) ; // function declaration
int main() {
char mychar = 'Z' ;
char * myptr ;
int rc ; // return code
myptr = &mychar ; // Initialize myptr pointer to the address of mychar.
// mychar will be Z
printf("main: before myfunc() call, mychar = %c\n", mychar) ;
printf("main: before myfunc() call, myptr = %p\n", myptr) ;
// Call myfunc(), using a call be reference scheme. The pointer to the
// actual value of mychar will be placed on the stack. myfunc() can
// now access the original mychar variable.
rc = myfunc(myptr) ; // function call
// Print out the value of mychar. We passed a pointer to mychar,
// and function myfunc() changed the value of it through indirection.
printf("main: after myfunc() call, mychar = %c\n", mychar) ;
printf("main: after myfunc() call, myptr = %p\n", myptr) ;
return 0 ;
}
int myfunc(char * xxx) { // function definition
// report the incoming value.
printf("xxx value should be Z, and it is: %c \n", *xxx ) ;
printf("xxx pointer is is: %p \n", xxx ) ;
// Through pointer xxx, variable the value to a new value.
*xxx = 'H' ;
// This shows that the value was changed.
printf("xxx value should be H, and it is: %c \n", *xxx) ;
return 0 ;
}
Now, let's focus on another aspect of getting all three (function declaration, call and definition) to match - the return value.
Here's the first example repeated to focus on the the return type.
Code:
#include <stdio.h>
int myfunc(char) ; // function declaration
int main() {
char mychar = 'Z' ;
int rc ; // return code
// mychar will be Z
printf("main: before myfunc() call, mychar = %c\n", mychar) ;
// Call myfunc(), using a call be value syntax. A copy of the
// actual value of mychar will be placed on the stack. myfunc() will
// never have access to the original mychar variable.
rc = myfunc(mychar) ; // function call
// Print out the value of mychar. It will still be Z, because
// function myfunc() changed the copy of mychar that was placed
// on the stack. This now proves that function myfunc() did not
// use the original value of mychar - it only changed a temporary
// copy of it that was on the stack.
printf("main: after myfunc() call, mychar = %c\n", mychar) ;
return 0 ;
}
int myfunc(char xxx) { // function definition
// report the incoming value.
printf("xxx should be Z, and it is: %c \n", xxx ) ;
// Change variable xxx to a new value.
xxx = 'H' ;
// This shows that the value was changed.
printf("xxx should be H, and it is: %c \n", xxx) ;
return 0 ;
}
Declaration: For myfunc(), the return type of int is declared in the function declaration.
Definition: myfunc() repeats the same "declaration" again in the definition, stating it will return an int value. And, indeed, it issues a return 0 ; before it exits.
Call: When called, the call needs to do something with int that is returned from the call to myfunc(). It does this by assigning the value to the variable rc. Again, all threes match.
Also, note the green code above. The exact same thing is being done for main() - we just don't have a function declaration for main().
Hope this helps.
Todd