Incompatible types in assignment

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • billiabon
    New Member
    • Mar 2008
    • 4

    Incompatible types in assignment

    Hello,everybody ! I need your help! My problem is this assignment

    [CODE=c]char pnm[10];
    void enqueue(int pd,char pnm[10],int pnum,int ptm,struct queue *z)

    {struct node *p;

    p=(struct node *)malloc(sizeof (struct node)); // give me memory such big

    p->id = pd;

    p->name = pnm; here is "incompatib le types in assignment" for the gcc

    p->num_quant=pnum ; [/CODE]


    Which is the appropiate assignment? Why?
    Last edited by Ganon11; Mar 7 '08, 02:59 PM. Reason: Please use the [CODE] tags provided.
  • mac11
    Contributor
    • Apr 2007
    • 256

    #2
    Originally posted by billiabon
    Hello,everybody ! I need your help! My problem is this assignment

    char pnm[10];
    void enqueue(int pd,char pnm[10],int pnum,int ptm,struct queue *z)

    {struct node *p;

    p=(struct node *)malloc(sizeof (struct node)); // give me memory such big

    p->id = pd;

    p->name = pnm; here is "incompatib le types in assignment" for the gcc

    p->num_quant=pnum ;


    Which is the appropiate assignment? Why?
    What type is p->name? Are you sure don't mean to copy the array contents instead of it's address?

    Comment

    • billiabon
      New Member
      • Mar 2008
      • 4

      #3
      Thanks for your answer! With the assignment
      p->name = pnm; i want to copy the content of array pnm to the field "name" of the structure node which the pointer p points. I don't want to copy any address

      Comment

      • Parul Bagadia
        New Member
        • Mar 2008
        • 188

        #4
        Originally posted by billiabon
        Thanks for your answer! With the assignment
        p->name = pnm; i want to copy the content of array pnm to the field "name" of the structure node which the pointer p points. I don't want to copy any address
        But how can u copy an entire array in one field?
        Dont you think your field should also be an array;
        whenever an incompatible erreor is coming ; it mens your assigning something wrong; other than expected to a variable.
        And its quite obvious that you cant store an entire array in single variable!

        Comment

        • billiabon
          New Member
          • Mar 2008
          • 4

          #5
          Hello! You're right but if the field is a char array 10 bytes long and the pnm is char array 10 bytes long then why the problem occurs?

          Comment

          • mac11
            Contributor
            • Apr 2007
            • 256

            #6
            Originally posted by billiabon
            Hello! You're right but if the field is a char array 10 bytes long and the pnm is char array 10 bytes long then why the problem occurs?
            The "=" doesn't copy array contents it just tries to copy the element you give it (in this case the array start address)

            You will have to use a function such as strncpy() or memcpy() or something to actually copy the contents from one array to another.

            Comment

            • billiabon
              New Member
              • Mar 2008
              • 4

              #7
              Thank you for your advises Parul Bagadia and mac11! They were very helpful!

              Comment

              Working...