I am writing a phonebook programe,the programe is below, and an error [Linker error] undefined reference to `WinMain@16' is appear.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char name [500][500];
char tel [500][500];
char emailaddress [500][500];
void entername();
void sort ();
void searchbyname();
void searchbyphoneno();
void searchbyemailaddress();
void menu ();
void searchmethod ();
void backtomenu();
void end();
void add ();
void show ();
void entername () {
int input;
}
void searchbyname() {
int input;
printf("Enter name:\n\n\n\n\n\n\n\n\n\n");
}
void searchbyphoneno() {
int input;
printf("Enter phone no.:\n\n\n\n\n\n\n\n\n\n");
}
void searchbyemailaddress() {
int input;
printf("Enter email address:\n\n\n\n\n\n\n\n\n\n");
}
void searchmethod() {
int input,name;
printf("1. Search by name\n");
printf("2. Search by phone no.\n");
printf("3. Search by email address\n");
printf("--------------------------------------------------------------------------------");
do{
printf("Enter your choice: ");
scanf("%d", &input );
if ( input!=1 || input!=2 || input!=3 ) {
printf("Wrong input! Please input again!\n");
}
}while ( input<=0 || input>3 );
if ( input==1 ) {
system("CLS");
searchbyname();
backtomenu();
}
if ( input==2 ) {
system("CLS");
searchbyphoneno();
backtomenu();
}
if( input==3 ) {
system("CLS");
searchbyemailaddress();
backtomenu();
}
}
void backtomenu() {
int input;
printf("1. Back to menu\n");
printf("--------------------------------------------------------------------------------");
do{
printf("Enter your choice: ");
scanf("%d", &input );
if ( input!=1 ) {
printf("Wrong input! Please input again!\n");
}
}while ( input<1 || input>1 );
if ( input==1 ) {
system("CLS");
menu() ;
}
}
void end () {
system("CLS");
printf("\n\n\n\n\n");
printf(" {+-+-+-+-+-+End+-+-+-+-+-+}\n\n\n\n\n\n\n\n\n\n");
}
void menu () {
int input;
printf("*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~Address book~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*\n");
printf("1. Name list\n");
printf("2. Search\n");
printf("3. Add name and information\n");
printf("4. End\n");
printf("--------------------------------------------------------------------------------");
do{
printf("Enter your choice: ");
scanf("%d", &input );
if ( input!=1 || input!=2 || input!=3 || input!=4 || input!=5 ) {
printf("Wrong input! Please input again!\n");
}
}while ( input<=0 || input>5 );
if ( input==1 ) {
system("CLS");
show();
printf("\n");
backtomenu();
}
if ( input==2 ) {
system("CLS");
printf(" ~~~~~~~~~~~~~~~~~~~~Search~~~~~~~~~~~~~~~~~~~\n");
searchmethod ();
}
if( input==3 ) {
system("CLS");
add();
backtomenu();
}
I get no error. At least not in compiling. However, I tidied up your code a bit. As well, please use [code][/code] notation in order to make your code readable.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char name [500][500];
char tel [500][500];
char emailaddress [500][500];
void entername();
void sort ();
void searchbyname();
void searchbyphoneno();
void searchbyemailaddress();
void menu ();
void searchmethod ();
void backtomenu();
void end();
void add ();
void show ();
void entername ()
{
//int input;
}
void searchbyname()
{
//int input;
printf("Enter name:\n\n\n\n\n\n\n\n\n\n");
}
void searchbyphoneno()
{
// int input;
printf("Enter phone no.:\n\n\n\n\n\n\n\n\n\n");
}
void searchbyemailaddress()
{
// int input;
printf("Enter email address:\n\n\n\n\n\n\n\n\n\n");
}
void searchmethod()
{
int input;//,name;
printf("1. Search by name\n");
printf("2. Search by phone no.\n");
printf("3. Search by email address\n");
printf("--------------------------------------------------------------------------------");
do{
printf("Enter your choice: ");
scanf("%d", &input );
if ( input!=1 || input!=2 || input!=3 )
printf("Wrong input! Please input again!\n");
}while ( input<=0 || input>3 );
if ( input==1 )
{
system("CLS");
searchbyname();
backtomenu();
}
if ( input==2 )
{
system("CLS");
searchbyphoneno();
backtomenu();
}
if( input==3 )
{
system("CLS");
searchbyemailaddress();
backtomenu();
}
}
void backtomenu()
{
int input;
printf("1. Back to menu\n");
printf("--------------------------------------------------------------------------------");
do{
printf("Enter your choice: ");
scanf("%d", &input );
if ( input!=1 )
printf("Wrong input! Please input again!\n");
}while ( input<1 || input>1 );
if ( input==1 )
{
system("CLS");
menu();
}
}
void end ()
{
system("CLS");
printf("\n\n\n\n\n");
printf(" {+-+-+-+-+-+End+-+-+-+-+-+}\n\n\n\n\n\n\n\n\n\n");
}
void menu ()
{
int input;
printf("*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~Address book~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*\n");
printf("1. Name list\n");
printf("2. Search\n");
printf("3. Add name and information\n");
printf("4. End\n");
printf("--------------------------------------------------------------------------------");
do{
printf("Enter your choice: ");
scanf("%d", &input );
if ( input!=1 || input!=2 || input!=3 || input!=4 || input!=5 )
printf("Wrong input! Please input again!\n");
}while ( input<=0 || input>5 );
if ( input==1 ) {
system("CLS");
show();
printf("\n");
backtomenu();
}
if ( input==2 ) {
system("CLS");
printf(" ~~~~~~~~~~~~~~~~~~~~Search~~~~~~~~~~~~~~~~~~~\n");
searchmethod ();
}
if( input==3 ) {
system("CLS");
add();
backtomenu();
}
if ( input==4 )
end ();
}
void add(){
int i;
char a='a';
FILE* f;
printf(" ~~~~~~~~~~~~~~~~~~~~Add name and information~~~~~~~~~~~~~~~~~~~~~\n");
printf("Enter name: ");
gets(name[1]);
gets(name[1]);
printf("Enter telephone number: ");
gets(tel[1]);
printf("Enter Email address: ");
gets(emailaddress[1]);
if((f=fopen("address.txt","a"))==NULL)
printf("Error!!");
else{
fputs(name[1],f);
fputc('\n', f);
fputs(tel[1],f);
fputc('\n', f);
fputs(emailaddress[1],f);
fputc('\n', f);
fclose(f);
sort ();
}
}
void show () {
char a='a';
FILE* f;
printf(" ~~~~~~~~~~~~~~~~~~~~Name list~~~~~~~~~~~~~~~~~~~~~\n");
if((f=fopen("address.txt","r"))==NULL){
printf("Error!!");
}
else{
do{
a=fgetc(f);
if( a != EOF)
printf("%c",a);
}while ( a!= EOF);
fclose(f);
}
}
void sort () {
char temp[500];
int i,j;
for(i=0; i< 500; i++) {
for(j=i; j<499;j++){
if(strcmp(name[j],name[j+1])==1){
strcpy(temp,name[j]);
strcpy(name[j],name[j+1]);
strcpy(name[j+1],temp);
}
}
}
}
int main () {
menu();
system("PAUSE");
return 0;
}
It's worth mentioning that I can see a few other problems in the code, though. For instance, in menu(), your conditional statement allows values of input from 1 to 5, however, should input==5, there is no action after the do-while for input==5. Not to mention the fact that you could simply make the conditional statement if(input>4 || input < 1).
Oh, and system() is the Devil.
And you can simplify those lists of printf()'s to just one by using '\n' for a new line. printf("Hi\nMy username is Wasabi\nDid you know that's a Japanese spice based off horseradishes?");
That outputs
1 2 3
Hi
My username is Wasabi
Did you know that's a Japanese spice based off horseradishes?
As well, the first four or so functions have int input but do nothing with it. Hell, the first function as a whole does absolutely nothing.