Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8726635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:17:21+00:00 2026-06-13T08:17:21+00:00

Writing a server/client program and getting these error on build with Netbeans: dbserver.c:195: warning:

  • 0

Writing a server/client program and getting these error on build with Netbeans:

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

Here’s the code in question:

//------------------------------------------------------------------------------
//                            Static Definitions
//------------------------------------------------------------------------------

#define WORD_LENGTH 32 //size of transmission & 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 & 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 *)&client_address, 
                                &client_address_length);

        if (slave_socket < 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(&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(&s.msg)) == 0) //search for preexisting word
            {
            if ((db_insert(&s.msg)) > 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(&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(&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 < 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 < 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<word_count ; i++)
    {
    if (strcmp(word, dictionary[i]) == 0)
        return 1;
    } //end for

    return 0;
} //end db_lookup
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------

I’ve excluded the preprocessor directives and the listen_socket_TCP function (in another source file).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:17:22+00:00Added an answer on June 13, 2026 at 8:17 am

    First, those are warnings, not errors…

    Anyway, looks like the problem is with how you’re passing the strings:
    dbserver.c:211: warning: passing argument 1 of 'db_lookup' from incompatible pointer type

    the db_lookup() is looking for a const char * such as when it’s used here:

     if (db_lookup("cti"))
    

    You’re passing it:

       if ((db_lookup(&s.msg)) == 0) //search for preexisting word 
    

    The address of the char pointer from the structure, if you just pass it:

       if ((db_lookup(s.msg)) == 0) //search for preexisting word 
    

    that should fix that type of warning.

    Second, remove the \0s from your sprintf’s to get rid of the two warnings about:
    warning: embedded '\0' in format

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a basic UDP Client-Server program and wasn't getting the expected results
I am writing a client/server program using C sockets. I am specifying that the
So I'm writing a program that is suppose to run forever (client server stuff)
I'm writing a client for a server program written in C++. As is not
I'm writing a client application to communicate with a server program via UDP. The
I am writing a simple C# tcp client and server program. The server will
hey I'm writing on an Server-Client program but when my client sends something, it
I'm writing a program that basically perform server-client relationship. When i run my client
i am writing a simple client/server chat program with indy 10 (blocking mode) and
Hi I am writing a simple client-server program. In this program I have to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.