ok so i am trying to put a menu function on the server side of a server client talk program. i would like to know if i am doing this correctly. i am also receiving a error that displays this...
serve.c: In function âstr_echoâ:
serve.c:48: error: âairlineâ undeclared (first use in this function)
serve.c:48: error: (Each undeclared identifier is reported only once
serve.c:48: error: for each function it appears in.)
serve.c:48: error: expected â;â before âblueskyâ
serve.c:65: error: âblueskyâ undeclared (first use in this function)
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/types.h>
#define MAXLINE 4096
#define SA struct sockaddr
#define SERV_PORT 9877
#define LISTENQ 1024
#define EINTR 0
void str_echo(int sockfd);
int main(int argc,char **argv)
{ int listenfd,connfd,errno;
pid_t childpid;
socklen_t clilen;
struct sockaddr_in cliaddr, servaddr;
listenfd=socket(AF_INET,SOCK_STREAM,0);
bzero(&servaddr,sizeof(servaddr));
servaddr.sin_family= AF_INET;
servaddr.sin_addr.s_addr= htonl(INADDR_ANY);
servaddr.sin_port= htons(SERV_PORT);
bind(listenfd,(SA*) &servaddr,sizeof(servaddr));
listen(listenfd,LISTENQ);
for(;;)
{ clilen=sizeof(cliaddr);
connfd=accept(listenfd,(SA*) &cliaddr, &clilen);
if((childpid=fork())==0)
{ close(listenfd);
str_echo(connfd);
exit(0);
}
close(connfd);
}
}
void str_echo(int sockfd)
{ ssize_t n, errno;
char buf[MAXLINE];
airline bluesky;
char choice;
int done=0;
int search_id;
int seat_counter=1;
again:
n=read(sockfd,buf,MAXLINE-1);
fputs(buf,stdout);
fgets(buf,MAXLINE,stdin);
write(sockfd,buf,MAXLINE);
printf( "***************************************\n");
printf("******BlueSky Airline Reserve System*****\n");
printf("****************************************\n");
while(!done)
{ choice=bluesky.menu();
switch(choice)
{
case (1):bluesky.make_reservation(seat_counter);
seat_counter++;
break;
case (2):printf("enter the id num of reservation you want to cancel: ");
//search_id;
bluesky.cancel_reservation(search_id);
break;
case (3):printf("enter the id num you want to search for the guest: ");
//search_id;
bluesky.search_pass(search_id);
break;
case (4):bluesky.change_reservation();
break;
case (5):bluesky.print();break;
case (6):bluesky.reports(); break;
case (7):printf("check in report is not working");break;
case (8):printf("thanks for using the system!");
done=1;
break;
default:printf("invalid choice, choose again: ");
break;
}
}
if(n<0 && errno==EINTR)
{ goto again;
}else if(n<0)
{ fprintf(stderr,"str_echo: read error");
exit(1);
}
}