title: Trouble with C Pointers with a Server/Client
body: <p>Writing a server/client program and getting these error on build with Netbeans:</p>
  
  <pre><code>dbserver.c:195: warning: embedded '\0' in format
  dbserver.c:211: warning: passing argument 1 of 'db_lookup' from incompatible pointer type
  dbserver.c:213: warning: passing argument 1 of 'db_insert' from incompatible pointer type
  dbserver.c:241: warning: passing argument 1 of 'db_delete' from incompatible pointer type
  dbserver.c:257: warning: passing argument 1 of 'db_lookup' from incompatible pointer type
  dbserver.c:287: warning: embedded '\0' in format
  </code></pre>
  
  <p>Here's the code in question:</p>
  
  <pre><code>//------------------------------------------------------------------------------
  //                            Static Definitions
  //------------------------------------------------------------------------------
  
  #define WORD_LENGTH 32 //size of transmission &amp; word length (31 characters + \0)        
  #define DICTIONARY_SIZE 100 //size of dictionary word count
  
  
  
  //------------------------------------------------------------------------------
  //                       Message Structure Definition
  //------------------------------------------------------------------------------
  
  typedef struct message 
  {
      int msg_type; //message code used to call database functions
      int msg_size; //expected size of message in transit
      char msg[32]; //payload capacity
  } message;
  
  
  
  //------------------------------------------------------------------------------
  //                Server Function &amp; Variable Initialization 
  //------------------------------------------------------------------------------
  
  char dictionary[DICTIONARY_SIZE][WORD_LENGTH]; //dictionary structure
  int word_count = 0; //dictionary word counter   
  int db_initialization(); //create db dictionary
  int db_insert(const char *word); //check for word, insert if not found
  int db_delete(const char *word); //remove word from dictionary if found
  int db_lookup(const char *word); //search dictionary for word
  int db_function(int fd); //db function call interface
  int errexit(const char *format, ...); //Khalid's error and exit
  //establishes socket to listen for connections
  int listen_socket_TCP(const char *service, int qlen); 
  
  
  //------------------------------------------------------------------------------
  //------------------------------------------------------------------------------
  //                            Main Function
  //------------------------------------------------------------------------------
  //------------------------------------------------------------------------------
  
  int main(int argc, char *argv[])
  {
      char *service = "27792"; //"Magic Port" to listen on
      struct sockaddr_in client_address; //IPv4 client address
      unsigned int client_address_length; //IPv4 client address length
      int master_socket; //TCP socket
      int slave_socket; //TCP socket spawned off of Master
  
      master_socket = listen_socket_TCP(service, WORD_LENGTH); //build database
  
  
  
  //------------------------------------------------------------------------------
  //        Dictionary Code Adapted from Material provided by Khalid
  //------------------------------------------------------------------------------
  
  
      db_initialization(); //initialize the database
      //seed the database
      db_insert("hello"); 
      db_insert("communication");
      db_insert("depaul");
      db_insert("cdm");
  
      //--------------------------------------------------------------------------
      //                   Test Database Function Operation
      //--------------------------------------------------------------------------
      if (db_lookup("cti"))
          printf("found\n");
      //end if
  
      else 
      {
          db_insert("cti");
          printf("'cti' has been inserted\n");
      } //end else
  
      if (db_delete("cdm"))
          printf("'cdm' has been successfully deleted\n");
      //end if
  
      else
          printf("cannot find 'cdm'.");
      //end else
  
  
  
      //--------------------------------------------------------------------------
      //                Forever Loop to Listen for Connections
      //--------------------------------------------------------------------------
      while (1) 
      {
      client_address_length = sizeof(client_address);
      slave_socket = accept(master_socket, (struct sockaddr *)&amp;client_address, 
                                  &amp;client_address_length);
  
          if (slave_socket &lt; 0) 
          errexit("accept: %s\n", strerror(errno));
          //end if
  
      printf("Connecting...\n");
      db_function(slave_socket);
      close(slave_socket);
      } //end while
  
  }
  //------------------------------------------------------------------------------
  //------------------------------------------------------------------------------
  //                              END MAIN FUNCTION
  //------------------------------------------------------------------------------
  //------------------------------------------------------------------------------
  
  
  
  
  
  //------------------------------------------------------------------------------
  //------------------------------------------------------------------------------
  //                            Server Function Codes:
  //------------------------------------------------------------------------------
  //------------------------------------------------------------------------------
  
  
  
  //------------------------------------------------------------------------------
  //                       Execute Database Functionality
  //------------------------------------------------------------------------------
  
  int db_function(int fd)
  {   
      int finished = 0;
      char re[2];
      int x = -1;
  
      while (!finished) 
      {
      char buf[sizeof(message)];
      int cc;
      struct message *sptr;
  
          message s;
  
          cc = recv(fd, buf, sizeof(message), 0);
      printf("Received Bytes: %i\n", cc);
  
          sptr = (struct message *) buf;
  
          memcpy(&amp;s, sptr,sizeof(message));
  
          if (s.msg_size != strlen(s.msg))
          {
          x = -1;
          sprintf(re,"%d \0", x);
          send(fd, re, 2, 0);
          break;
      } //end if
  
  
          //----------------------------------------------------------------------
          //           Message Code 1 - Insert Word into Dictionary
          //
          // Return  1: Successfully Inserted Word
          // Return  0: Word Exists in Dictionary Already
          // Return -1: Failed to Add Word to Dictionary
          //----------------------------------------------------------------------
  
      if (s.msg_type == 1)
          {
          if ((db_lookup(&amp;s.msg)) == 0) //search for preexisting word
              {
              if ((db_insert(&amp;s.msg)) &gt; 0) //insert word into dictionary
                  {
              x = 1; //word added successfully
          } //end insert if
  
                  else
                      x = -1;//unsuccessful in adding word
  
          } //end search and insert if
  
              else 
          x = 0;
  
              printf("Adding to dictionary: %s result %i\n", s.msg, x);
      } //end if message type 1
  
  
  
          //----------------------------------------------------------------------
          //           Message Code 2 - Delete Word from Dictionary
          //
          // Return  1: Successfully Deleted Word
          // Return  0: Word does not Exist in Dictionary
          // Return -1: Failed to Delete Word from Dictionary
          //----------------------------------------------------------------------
  
          if (s.msg_type == 2)
          {
          x = db_delete(&amp;s.msg);
          printf("Deleting from dictionary: %s result %i\n", s.msg, x);
      } //end if message type 2
  
  
  
          //----------------------------------------------------------------------
          //           Message Code 3 - Lookup Word in Dictionary
          //
          // Return  1: Successfully Found Word
          // Return  0: Word not FOund in Dictionary
          // Return -1: Function Failed
          //----------------------------------------------------------------------
  
      if (s.msg_type == 3)
          {
          x = db_lookup(&amp;s.msg);
          printf("Looking up from dictionary: %s result %i\n", s.msg, x);
      } //end if message type 3
  
  
  
          //----------------------------------------------------------------------
          //           Message Code 4 - Close Connection
          //----------------------------------------------------------------------
  
          if (s.msg_type == 4)
          {
          x = 1;
  
              printf("Closing connection: %s result %i\n", s.msg, x);
  
              break;
      } //end if message type 4
  
  
          printf("Words in dictionary: {");
  
          int c = 0;
          for (c=0; c &lt; word_count; c++)
          {
          printf("%s, ", dictionary[c]);
      }
  
          printf("}\n");
  
          sprintf(re,"%d\0", x);
  
          send(fd, re, 2, 0);
      } // end while(!finished)
  
      return 0;
  } //end db_function
  //------------------------------------------------------------------------------
  //------------------------------------------------------------------------------
  
  
  
  
  
  //------------------------------------------------------------------------------
  //                         Database Initialization
  //------------------------------------------------------------------------------
  
  int db_initialization()
  {
      word_count = 0;
      return 1;
  } //end db_initialization
  //------------------------------------------------------------------------------
  //------------------------------------------------------------------------------
  
  
  
  
  
  //------------------------------------------------------------------------------
  //                       Insert Word into Dictionary
  //------------------------------------------------------------------------------
  int db_insert(const char *word)
  {
      strcpy(dictionary[word_count], word);
      word_count++;
      return word_count;
  } //end db_insert
  //------------------------------------------------------------------------------
  //------------------------------------------------------------------------------
  
  
  
  
  
  //------------------------------------------------------------------------------
  //                       Delete Word from Dictionary
  //------------------------------------------------------------------------------
  int db_delete(const char *word)
  {
      int i;
      for (i=0 ; i &lt; word_count ; i++)
      {
      if (strcmp(word, dictionary[i]) == 0) 
          {
          word_count--;
  
              strcpy(dictionary[i], dictionary[word_count]);
  
              return 1;
          } //end if
  
      } //end for
  
      return 0;
  } //end db_delete
  //------------------------------------------------------------------------------
  //------------------------------------------------------------------------------
  
  
  
  
  
  //------------------------------------------------------------------------------
  //                        Lookup Word in Dictionary
  //------------------------------------------------------------------------------
  int db_lookup(const char *word)
  {
      int i;
      for (i=0 ; i&lt;word_count ; i++)
      {
      if (strcmp(word, dictionary[i]) == 0)
          return 1;
      } //end for
  
      return 0;
  } //end db_lookup
  //------------------------------------------------------------------------------
  //------------------------------------------------------------------------------
  </code></pre>
  
  <p>I've excluded the preprocessor directives and the listen_socket_TCP function (in another source file).</p>