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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:50:21+00:00 2026-05-24T03:50:21+00:00

Off lately I have taken up the task to understand and learn C. Right

  • 0

Off lately I have taken up the task to understand and learn C. Right now I was learning about structures and pointer arrays. I have a problem. I want to populate a pointer array with values. Below is my code:

           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;

         int j =0;
         int i =0;

      outObj.profiles[j].data = malloc(10);

      for(i=0;i<10;i++)
          {
         if (j=0)
             {
           outObj.profiles[j][i] = 1 2 3 4 5 6 7 8 9 10;
         }
         else 
             {
        j=1;
         }
      }

      for(i=0;i<10;i++)
          {
        if (j=1)
            {
           outObj.profiles[j][i] = 1 2 3 4 5 6 7 8 9 10;
        }
      }

Is the above approach the way to go or am I completely offtrack. MAXPROFILES is 2 (which means only 0 and 1).

  • 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-24T03:50:22+00:00Added an answer on May 24, 2026 at 3:50 am

    You cannot assign like this

    outObj.profiles[j][i] = 1 2 3 4 5 6 7 8 9 10;
    

    outObj.profiles[j] is profile_t instance.
    outObj.profiles[j].data is char*.
    I suppose that you want to assign that integers to data.
    First of all you should allocate memory for both j values.

    outObj.profiles[0].data = malloc(10);
    outObj.profiles[1].data = malloc(10);
    

    I suggest you to replace your code with loops with something like this

    for(i=0;i<10;i++) {
        outObj.profiles[0].data[i] = i+1;
        outObj.profiles[1].data[i] = i+1;
    }
    

    The result is same but it is much cleaner to read and understand.

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

Sidebar

Related Questions

First off, I'm using Access 2000 and DAO. I have code that executes a
First off, the jQuery datepicker works fine with classes when doing a fresh page
First off, I am cross-posting this from Server Fault because I did not receive
First off: Everything works , but I would like to fine tune this a
First off, this is the error I am getting java.lang.OutOfMemoryError at coderaustin.com.FileEncryptor.encryptFile(FileEncryptor.java:56) at coderaustin.com.Main.onCreate(Main.java:41)
First off I should forewarn you that I am a new grad(and EE at
First off, apologies if this is a complete noob question which could easily be
Let me start off by stating that I know the assignment operator in C#
After an ImageView translates off the screen via a TranslateAnimation object, I want to
So usually when EXC_BAD_ACCESS happens when I'm debugging my (largely c++ based) iphone app,

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.