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

}

So, what is airline at line 48?

well from what i am trying to do is take a program from c++ and convert it to c, so should airline be a struct? this is what it looks like in c++

class airline
{       private:

        struct passenger
        {       int id;
                int res_num;
                string phone;
                int seat;
                char menu;
                string lname;
                string fname;
                passenger* next;
        };
        passenger *head, *cur, *pre, *nptr;

        public:
                airline();
                char menu();
                void make_reservation(int seat_counter);
                void print();
                bool search_pass(int key);
                void change_reservation();
                void reports();
                bool cancel_reservation(int key);

well from what i am trying to do is take a program from c++ and convert it to c, so should airline be a struct?

Yes.

this is what it looks like in c++

class airline
{       private:

        struct passenger
        {       int id;
                int res_num;
                string phone;
                int seat;
                char menu;
                string lname;
                string fname;
                passenger* next;
        };
        passenger *head, *cur, *pre, *nptr;

        public:
                airline();
                char menu();
                void make_reservation(int seat_counter);
                void print();
                bool search_pass(int key);
                void change_reservation();
                void reports();
                bool cancel_reservation(int key);

and that's approximately how it would look in C (don't forget to alter strings into char * and treat them appropriately):

typedef struct passenger
        {       int id;
                int res_num;
                string phone;
                int seat;
                char menu;
                string lname;
                string fname;
                struct passenger* next;
        } passenger;

typedef struct airline
{
        passenger *head, *cur, *pre, *nptr;
} airline;
 
airline *     airline_init();
char           menu(airline *);
void           make_reservation(airline * int seat_counter);
//etc

i would put this on the server side of the program correct?

ok so i put the struct in the server side, but now i am getting this error. can u explain it to me.

serve.c:36: error: expected â=â, â,â, â;â, âasmâ or â__attribute__â before âsearch_passâ
serve.c:39: error: expected â=â, â,â, â;â, âasmâ or â__attribute__â before âcancel_reservationâ
serve.c: In function âstr_echoâ:
serve.c:97: error: âairlineâ has no member named âmenuâ
serve.c:100: error: âairlineâ has no member named âmake_reservationâ
serve.c:105: error: âairlineâ has no member named âcancel_reservationâ
serve.c:109: error: âairlineâ has no member named âsearch_passâ
serve.c:111: error: âairlineâ has no member named âchange_reservationâ
serve.c:113: error: âairlineâ has no member named âprintâ
serve.c:114: error: âairlineâ has no member named âreportsâ

i just decided not to do the program. but thank u for the help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.