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 7829401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:44:44+00:00 2026-06-02T10:44:44+00:00

I have two structures as shown below struct server{ // some members }; struct

  • 0

I have two structures as shown below

struct server{
    // some members
};

struct msg{
    struct server* servers;
};

Then I do this.

struct msg msg1;
struct server s1,s2;

msg1.servers = (struct server *)malloc(2*sizeof(struct server));
msg1.servers[0] = &s1; // compilation error 
msg1.servers[1] = &s2;  // compilation error

This code does not compile and giving the following error : incompatible types when assigning to type ‘struct server’ from type ‘struct server *’.

What am I doing wrong?

  • 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-02T10:44:45+00:00Added an answer on June 2, 2026 at 10:44 am

    The problem here is that the expression msg1.servers[0] producets a struct server but you’re providing a struct server* (a pointer type vs a non-pointer type). There are two ways to fix this

    The first is to simply provide the struct server instances by value as the code expects

    msg1.servers[0] = s1;
    msg1.servers[1] = s2;
    

    This will work if struct server is a type that behaves properly when copied around.

    The second is necessary if you want to continue using struct server* in the struct msg. In this case you need a double pointer to store the server pointers. And you need to adjust your malloc statement appropriately

    struct msg{
        struct server** servers;
    };
    
    msg1.servers = malloc(2*sizeof(struct server*));
    msg1.servers[0] = &s1; 
    msg1.servers[1] = &s2;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some HTML that I need to toggle between two structures - one
I have two tables afrostarprofiles and afrostarvvideos created as shown below. artistid field in
I have these two data structures that I continually find myself choosing between when
Say I have a database called Poll and have these two table structures. poll
I have two tables with the following (simplified) structures: table "Factors" which holds data
In my code base I find that two modules have structures with the same
Let's say I have a simple parent->child class structure as shown below Public Class
I have some data I have to show through two JTables; the data is
I have two table structures like these: episodes ( episode_id MEDIUMINT(8) UNSIGNED NOT NULL
I have two UpdatePanels, UpdatePanel1 and UpdatePanel2. I am inside of a server-side event.

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.