Need help with function call!

After compiling i am getting a "a function definition not allowed here before a '{' token" error. Need help fixing this. Line 90. And also I'm getting a expect '}' at end of input error.
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>


void newrec( FILE * fPtr);		
void rec( FILE * fPtr); 	
void update (FILE * uPtr);		
void deleterec(FILE *dfPt);
void updatefile( FILE * uPtr);


typedef struct guests
{
int room_no;
char name[30];
char address[50];
char phone[10];
int period;
}guests;

guests guest[50];
	

int main()
{
int option;
FILE *cfPtr;

if( (cfPtr=fopen("hotel.txt", "a+" ) ) ==NULL ) {
    printf("File could not be opened\n");
}
else
{
do{	
  printf ("\t**********************************************************************\n");
  printf ("\t*                                                                    *\n");
  printf ("\t*					      W E L C O M E								  *\n");
  printf ("\t*																	  *\n");
  printf ("\t* 							   T O									  *\n");
  printf ("\t*																	  *\n");
  printf ("\t*		    T R A N Q U I L  P A R A D I S E  H O T E L 			  *\n");
  printf ("\t*																	  *\n");
  printf ("\t*	       	H O T E L  M A N A G E M E N T  S Y S T E M	    		  *\n");
  printf ("\t*																	  *\n");
  printf ("\t*																	  *\n");
  printf ("\t**********************************************************************\n");	
  printf ("\n");
  system ("pause\n");
  system ("cls");
  printf ("\n\tPlease select your option from the list below:\n\n\n");
  printf ("\t 1. Add new record\n");
  printf ("\t 2. View Records\n");
  printf ("\t 3. Update/Edit Record\n");
  printf ("\t 4. Delete Record\n");
  printf ("\t 5. Exit\n");
  system ("pause\n");
  system ("cls");

  scanf ("%d",&option);
  switch (option)

 {
  	case 1: system("cls");
	  		newrec(cfPtr);
  			break;
       			   
  	case 2: system("cls");
	  		rec(cfPtr);
			break;
	   
  	case 3: system("cls");
	  		update(cfPtr);
			break;
			
	case 4: system("cls");
	  		deleterec(cfPtr);
			break;
			
  	case 6: exit(0);
	 
  	default: 
	printf ("\n INVALID SELECTION!!!\n");
	system  ("pause\n");
	return 0;
 }

 void newrec(FILE *fPtr)
{

int answer;
int i = 1;

if(( cfPrt=Fopen("hotel.txt", "a+")) ==NULL){
		printf(" File could not be opened\n");
 }

else
{
	do{

	 	system ("cls");
	 	system (" color 3a");
	 	
	 	printf ("Enter full name:\n\n");
		scanf ("%s", guest[i].name);
		
		printf ("Enter address:\n\n");
		scanf ("%s", guest[i].address);
		
		printf ("Enter room number:");
		scanf ("%s", guest[i].room_no);
		
		printf ("Enter phone number:");
		scanf ("%d", guest[i].phone);
		
		printf ("Enter how long guest will stay:");
		scanf ("%d", guest[i].period);
		 
		fprintf(fPtr, "%-10s%-10s%-10d%-10s\n", guest[i].name, guest[i].address, guest[i].room_no, guest[i].phone, guest[i].period);
		       
		printf("Do you want to add another guest? (Yes=1/No=2)\n");
		scanf("%d",&answer);
		i = i + 1
	
	}while (answer!= 2);
}
 fclose(fPtr);
   system("cls"); 
   printf("n\\t^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^\n");
   pri	ntf("\n\t-------Guest Was Successfully Added--------\n");
   printf("\n\t^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^\n");
                                  
   system ("\npause");
   main();
}

 
 void rec( FILE * pPtr)
 {
	updatefile(pPtr);
    system("cls"); 
	int i = 1;
	 
     if ( ( pPtr= fopen("hotel.txt", "r") )==NULL ) 
    {
      printf("File couldn't' be opened.\n");
    }
 	else
 	{
 		printf("%s %s %d %2.2f\n", "Guest Name", "Adress", "Room #", "Phone #", "Period");
 		fscanf(pPtr, "%s%s%d%d%s\n", guest[i].name, guest[i].address, guest[i].room_no, guest[i].phone, guest[i].period);
 		
 	}
 optmenu()
 }
 
 void update( FILE * uPtr) 
 {
 	char name[30];
 	int newperiod
 	int 1 = 1;
 	
 		if ( ( uPtr = fopen("hotel.txt", "r")) == NULL ) {
		printf("File cannot be opened\n");
	}
	else
	{
		printf("\nPlease enter guest name\n");
		scanf("%s", name);
		fscanf(uPtr, "%s%s%d%d%s\n", guest[i].name, guest[i].address, guest[i].room_no, guest[i].phone, guest[i].period); 
		while(!feof (uPtr)){
					
			if (strcmp(name, guest[i].period) == 0 )
				{
				printf("Enter new period\n");
				scanf("%d", &newperiod);
				guest[i].period = newperiod;
				
				printf("%-10s%-10s%-10d%-10s\n", guest[i].name, guest[i].address, guest[i].room_no, guest[i].phone, guest[i].period);
				updatefile(uPtr);			
			}
			i = i + 1;
			fscanf(uPtr, "%s%s%d%d%s\n", guest[i].name, guest[i].address, guest[i].room_no, guest[i].phone, guest[i].period); 
			
		}
		
		updatefile(uPtr);
		fclose(uPtr);
		
	}
}
 	
 }
 
void updatefile( FILE * uPtr) 

{
	int i;
	if ( ( uPtr = fopen("hotel.txt", "w")) == NULL ) 
    {
	
    	printf("File cannot be opened\n");
	}
	
    else
	{
		for (i = 1; i < 50; i ++) 
        {
			if (guest[i].period != 0)
            {
				fprintf("%s %s %d %d %s %2.2f\n", "Guest Name", "Adress", "Room #", "Phone #", "Period");
 				fscanf(pPtr, "%s%s%d%d%s\n", guest[i].name, guest[i].address, guest[i].room_no, guest[i].phone, guest[i].period);
			}
		
		}
	fclose(uPtr);	
	}
	
	
}
void deletecustomer(FILE *dPtr)
{
	  char name[30];
	  int i = 1;

	  if ( ( dPtr = fopen("guests.txt", "r")) == NULL ) 	{		
        printf("File cannot be opened\n");       
       }
       
	  else
	{
    system ("cls");
    printf("\tWho do you want to delete?\n");
	scanf ("\n\t%s", name);
		
	while (!feof(dPtr)) {
	fscanf(pPtr, "%s%s%d%d\n", guest[i].name, guest[i].address, guest[i].room_no, guest[i].phone, guest[i].period);
 				
    if (strcmp(name,guest[i].name)==0)
    {
           
    system ("pause");
	strcpy(guest[i].name , "");
	strcpy(guest[i].address, "");
	strcpy(guest[i].room_no, "");
	strcpy(guest[i].phone, "");
	strcpy(guest[i].period, "");
	printf("%d Guest has been deleteed\n", i);
	}
	i= i +1;
	}
	updatefile(dPtr);
	fclose(dPtr);
	system ("pause");
	main(); 
	}
}
Hi,

You are missing the while condition for the first do loop.

Don't ever call main() in your program - it will lead to a stack overflow. Use loops instead.

Your main menu should be in a function of it's own, as should the switch statement.

When using scanf, or fscanf - always make use of it's return value to see if it worked, otherwise you might have garbage input.

Try to avoid having global variables.

Line 209: This will miss the first value in the array . Arrays start at 0. The normal idiom for a for loop is:

for (i = 0; i < 50; i++)

This:
i = i + 1;

can be abbreviated to i++;

Some of your code looks similar, can you put those parts into a function of their own?

Line 86 effectively terminates the program - is that what you want? Put the switch into a while loop.

Hope this helps you out a bit :+)
Topic archived. No new replies allowed.