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

  • Home
  • SEARCH
  • 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 8857925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:42:27+00:00 2026-06-14T14:42:27+00:00

Im having trouble assigning to struct pointer in another struct pointer The structs looks

  • 0

Im having trouble assigning to struct pointer in another struct pointer

The structs looks like this:

header.h

typedef struct {
    int drawnlines;
    char *name;
} player;

typedef struct {
    char a, b;
    p *mover;
    p *previous;
} lastmove;

In another function Im calling another function that is supposed to change a pointer to this struct, this is also the function that gives me an warning:

program.c

#include header.h
.....
lastmove lmv;
lmv.mover=malloc(sizeof(player *));
lmv.previous=malloc(sizeof(player *));
player p;
p.drawnlines=0;
p.drawnlines=0;
strcpy(p.name, "patrik");
function(&lmv, &p);

.....
int
function(lastmove *lmv, player *p)
{
    lmv->a='b';
    lmv->b='a';
    lmv->previous=lmv->mover;
    lmv->mover=p;        // warning: assignment from incompatible pointer type
}

What is wrong in my code?

UPDATE: Now the code works, was a simple mistake. The struct "lastmove" is now changed to

typedef struct {
    char a, b;
    player *mover;
    player *previous;
} lastmove;
  • 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-14T14:42:28+00:00Added an answer on June 14, 2026 at 2:42 pm

    Well, in your code, mover is a pointer to type p, which isn’t defined anywhere – do you mean this?

    typedef struct {
        char a, b;
        player *mover;
        player *previous;
    } lastmove;
    

    Also, I think there’s an issue with your allocation. You’re allocating enough space for a player*, which is a pointer to a player, when what you need is enough space for a player.

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

Sidebar

Related Questions

I am having trouble assigning the value of an NSString to a char *
I am having trouble over simply assigning a value to a UI Button: //Assume
Having trouble framing this assertion in Rspec for my rails app. A User has
I am having trouble assigning a NSString to the text of a NSScrollView. I
I am having trouble with mysql triggers assigning primary key values. Consider my tables:
I’m having trouble getting a AJAX/JSON function to work correctly. I had this function
I am having some trouble getting this simple code to work: #pragma once #include
I'm having trouble aligning the roll-over elements of the main menu on this website...
Well new to the java stuff and having trouble with assigning a class attribute
I'm having trouble assigning an instance of a class to the following UITableViewController subclass:

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.