[Linker error] undefined reference to `WinMain@16'

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();
}

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();
return 0;

system("PAUSE");

}
}
Please help if you can.Thz.
Last edited on
please copy and past your code from your compiler and but code tags around it please. That is barely readable
I am just a beginner, and I don't know how to copy and past the code from the compiler...
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#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 ();

int main()
{
	menu();
	system("pause");
	return 0;
}

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("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);
			}
		}
}
}
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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#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.
the above compiles with no errors.

If you use a prototype which i recommend, put the function definition after the main which i have done

You also at times put too many {} braces

its a matter of preferance though. But pick one way and go with it.

In your code some times you did one thing and other times you did something else.

example

if(..........){
blah blh blah;
}

other times you would do this

if(.........)
blh blah blha; // i prefer this way to be honest
thank you so much:D
lol . yea I also didnt like the fact that you used ifs when you shouldve used if / else if etc

It's actually really important to know when to use each. A series of if's can all be true. If/Else If's can't. It becomes an either/or situation.

Big difference.

And I always get annoyed when I see
1
2
3
4
if(...)
{
   one_function();
}

I try to delete the brackets whenever they aren't necessary, but I might have missed a few in my revision of this code.
sorry for my inconvenient :(
Topic archived. No new replies allowed.