[C] Protoyping

Hi guys, quick question. How can I prototype this function? Usually for a function using the basic data types, I just do this:

void insertData(int);

The function below needs to get a data structure, and I really don't know how to prototype it as it's the first time I'd be prototyping a function that needs a data structure. A little help?

1
2
3
4
5
6
7
8
9
10
11
void displayData(struct Node *temp){
	if(!(MyNode)){
		printf("No data.");
	} else {
		printf("Elements are: \n");
		for(temp=MyNode; temp; temp=temp->next){
			printf("%d\n", temp->data);
		}
	}
	getch();
}
void displayData(struct Node *);
As you can see a prototype is generally the same as the first line of a definition, except you can omit parameters names and it needs a semicolon at the end.
Just wanna confirm something:

 
void insertData(int);


The reason why this worked is because there's only one parameter for this function, right?
The reason why it worked was because it matched the function definition itself, with name of the parameter omitted, though that is optional. Sometimes it is better to keep the parameter names in the prototype, as the use of meaningful names helps the reader to understand the purpose of each parameter and how it is intended to be used.

Usually I write the function first, then copy & paste the first line to give the prototype.
Last edited on
I see. Thanks for the heads up then.
Topic archived. No new replies allowed.