Grenage
May 11th, 2012, 12:51 PM
I'm dabbling with C, and am a little flustered over the use of a void function. Let's say I have a basic menu, and depending on which option is selected, a function is called:
#include <stdio.h>
void networkfail(void);
int main() {
int menuselection;
printf("\n\nYadda Yadda:\n\n");
printf("1) Option 1.\n");
printf("2) Option 2.\n");
printf("3)\n");
printf("4)\n");
printf("5) Quit.\n\n");
scanf("%d", &menuselection);
switch (menuselection) {
case 1:
networkfail();
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
default:
printf("That wasn't an option.");
break;
}
void networkfail() {
printf("Shame.");
}
return 0;
}
The compilation error is:
undefined reference to `networkfail'
What I don't understand, is why. As far as I am aware, the prototype is valid, and no parameters are required for the function. If I include 'void' in the function call, I'm informed that I have supplied too many parameters.
#include <stdio.h>
void networkfail(void);
int main() {
int menuselection;
printf("\n\nYadda Yadda:\n\n");
printf("1) Option 1.\n");
printf("2) Option 2.\n");
printf("3)\n");
printf("4)\n");
printf("5) Quit.\n\n");
scanf("%d", &menuselection);
switch (menuselection) {
case 1:
networkfail();
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
default:
printf("That wasn't an option.");
break;
}
void networkfail() {
printf("Shame.");
}
return 0;
}
The compilation error is:
undefined reference to `networkfail'
What I don't understand, is why. As far as I am aware, the prototype is valid, and no parameters are required for the function. If I include 'void' in the function call, I'm informed that I have supplied too many parameters.