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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:55:14+00:00 2026-05-24T05:55:14+00:00

Since two days I am playing with C and I come across new problem

  • 0

Since two days I am playing with C and I come across new problem all the time. Right now I want to do memcopy my data into a char buf, but I am encountering some problems: My code is below:

         int main(int argc, char *argv[])
        {
         int sockfd, portno, n;
         struct sockaddr_in serv_addr;
         struct hostent *server;
     unsigned char buf[1024];

        struct profile_t 
      {
        unsigned char length;
        unsigned char type;
        unsigned char *data;
      };

        typedef struct profile_datagram_t
      {
        unsigned char src[4];
        unsigned char dst[4];
        unsigned char ver;
        unsigned char n;
        struct profile_t profiles[MAXPROFILES];     
      } header;


      header outObj;

      outObj.src[0] =1;
  outObj.dst[0] = 2;
  outObj.ver = 1;
  outObj.n = 2;


  outObj.profiles[0].length = 10;
  outObj.profiles[0].type = 1;
  outObj.profiles[1].length = 10;
  outObj.profiles[1].type = 2;




  memcpy(buf,outObj.src,4);
  memcpy(buf+4,outObj.dst,4);
  memcpy(buf+8,outObj.ver,1);
  memcpy(buf+9,outObj.n,2);


  memcpy(buf+10,outObj.profiles[0].length,1);
  memcpy(buf+11,outObj.profiles[0].type,1);
  memcpy(buf=12,outObj.profiles[0].data,10);

I am getting the following errors:

warning: passing argument 2 of memcpy makes pointer from integer without a cast
error: incompatible types when assigning to type unsigned char[1024] from type int

The errors are for memcpy(). Can anyone explain me about memcpy() and also where I am going 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-05-24T05:55:14+00:00Added an answer on May 24, 2026 at 5:55 am

    You need to pass the address of the various fields of your structures. When you pass an array by name, that is automatically the address of the beginning of the array. But the non-array fields need the address-of operator &:

    memcpy(buf+10,&outObj.profiles[0].length,1);
    

    As an aside, this is better in case you change the type of length:

    memcpy(buf+10,&outObj.profiles[0].length,sizeof(outObj.profiles[0].length));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two DateTimes, one is the time 'since' and 'now' What I need,
Since two days I am trying to consume a WCF (.NET) Soap Service and
I'm using Apache Maven3 and since two or three days some dependencies can't be
note: using django/python/javascript/flash So its been two days since I'm stuck at the error.
Since I updated two days ago my Android SDK to version API 14 I'm
I just learned jQuery over the last two days, so I'm kind of new
Over the past few days i read a lot about Dependency Injection. Now since
Since, two methods with the same parameters but different return values will not compile.
Since I've started my first job as a professional software developer about two years
Since both a Table Scan and a Clustered Index Scan essentially scan all records

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.