Hi all,

Am fairly new to the programming world, but am kind of struggling along. I have written a piece of code for a client program with has given me some errors that i just can't see when compiling. The errors listed are :

 client.c: In function `main':
  client.c:118: error: syntax error before '-' token
  client.c: At top level:
  client.c:132: error: conflicting types for `close_socket'
  sockets.c.h:40: error: previous declaration of `close_socket'
  client.c:133: error: parse error before '}' token

And i have also listed the program below. I hope that someone can point out the errors in my ways. Thanks in advance for looking.

 /*client.c - demonstration client program. Written in C Nov '94 from
  Pascal version of Nov/Dec '93
  revised Oct 2005 to use stdio */

  #include <stdio.h>
  #include "sockets.c.h"

  main()
  {

     host_name       server;
     port_number     port;
     socket_id       local_socket;
     int             ok,i,len;
     socket_buffer   data;
     char id[50];
     char box[5];
     char ack[50];
     int boxlenerr;
     char view_data[256];

     printf("client ...\n");
     printf("please enter host server name\n");
     scanf("%s",server);
     printf("please enter server port number\n");
     scanf("%d",&port);    /* remember the "&" to allow scanf to store the input value */

     local_socket = create_socket();
     printf("client: socket %d created\n", local_socket);

     ok=connect_sockets(local_socket, server, port);
  /* socket is connected at this point */

     printf("Please enter your SetTopBox Number\t");
     scanf("%s",box);

     if (strlen(box) !=10)
       {
         printf("Incorrect box number, please try again later\n");
       }
     else
       {
         send_data(local_socket,box,strlen(box)+1);
         recv_data(local_socket,ack);
       }

     printf("Please enter your Customer ID\t");
     scanf("%s",id);

  if (strlen(id) !=4)
       {
         printf("Your ID number needs to be 4 digits long\n");
       }
     else
       {
         send_data(local_socket,id,strlen(id)+1);
         recv_data(local_socket,ack);
       }

     int option;
     option = 0;
     printf("NuTV SELECTION MENU");
     while (option !=4)
       {
          display_menu();
         option = get_selection();
         switch (option)
           {
               case 1: get_prog_ch();
               break;
               case 2 : get_prog_cat();
               break;
               case 3 : get_prog_sub();
               break;
           }
       }
     printf(" Thanks for calling Goodbye\n\n");

     if (ok < 0)
     {
        printf("failed to connect sockets\n");
     }
     else
     {
        printf("client: connection made to server, now use service\n");

        len=recv_data(local_socket,data);

        printf("client: %d bytes of data received\n",len);

        /* now display the data received, character by character */
        for (i=0;i<len;i++)
        {  printf("%c",data[i]);
        }
        printf("\n");
     }

  void display_menu()
       {
         printf("\n");
         printf("Please choose an option\n");
         printf("1-Choose programmes by channel number\n");
         printf("2-Choose programmes by category\n");
         printf("3-Choose programmes bt ctegory & sub-categroy\n");
         printf("4- Exit the system\n");
       }

     int get_selection()
       {
         int ch =0;
         while (ch >3 && ch <1)
           {printf("please enter your choice (1-3) and press return:\n");
           scanf("%d",&ch);
  }
         return (ch);
       }

     void get_prog-ch()
       {
         printf(" this gets you the channels");
       }

     void get_prog_cat()
       {
         printf(" By category");
       }

     void get_prog_sub()
       {
         printf("By sub category");
       }


  }

The problem is mis-matched braces '{' and '}'. delete line 119.

what is the semicolon doing on line 1?

hi,

Thanks have done that, think that the ; is a typo error. Now when i compile i get :


gcc -w stream_sockets.o client.c -o client
display_menu
get_selection
get_prog_ch
get_prog_cat
get_prog_sub
collect2: ld returned 1 exit status
*** Exit 1
Stop.

what is going on here ?

I would guess you call the ld system command from somewhere in your program and it returned with an error. But it's only a guess since there's no code posted to verify it.

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.