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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:10:28+00:00 2026-05-28T01:10:28+00:00

gcc 4.6.2 c89 Allocating memory for a 2D array and filling with characters. However,

  • 0

gcc 4.6.2 c89

Allocating memory for a 2D array and filling with characters.

However, I don’t seem to be filling as when I print nothing is displayed.

Am I doing something wrong here?

char **attributes = NULL;

/* TODO: Check for memory being allocated */
attributes = malloc(3 * sizeof(char*));
int i = 0;
int k = 0;

for(i = 0; i < 3; i++) {
    for(k = 0; k < 5; k++) {
        sdp_attributes[i] = malloc(5 * sizeof(char));
        sdp_attributes[i][k] = k;
    }
}

for(i = 0; i < 3; i++) {
    for(k = 0; k < 5; k++) {
        printf("attributes[i][k] [ %c ]\n", attributes[i][k]);
    }
}

Many thanks for any advice,

  • 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-28T01:10:29+00:00Added an answer on May 28, 2026 at 1:10 am

    Two major issues:

    First Issue:

    for(i = 0; i < 3; i++) {
        for(k = 0; k < 5; k++) {
            sdp_attributes[i] = malloc(5 * sizeof(char));
    

    You are reallocating sdp_attributes[i] at each iteration of the inner loop – thereby overwriting it each time. You probably wanted this instead:

    for(i = 0; i < 3; i++) {
        sdp_attributes[i] = malloc(5 * sizeof(char));
        for(k = 0; k < 5; k++) {
    

    Second Issue:

    sdp_attributes[i][k] = k;
    

    You are basically writing the lower ascii characters. Most of them are not printable.
    Something like this might do what you want:

    sdp_attributes[i][k] = k + '0';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

gcc 4.5.1 c89 I am trying to free some memory. However, when I check
gcc 4.6.2 c89 I have the following 2D array that I want to pass
gcc 4.5.1 c89 I have a buffer that is filled with char characters. I
gcc c89 I am getting a stack dump on this line: strcpy(comp->persons->name, Joe); However,
gcc 4.4.2 c89 I was just working on some pointers. However, with the program
gcc 4.4.2 c89 I re-engineering some code in c89. However, I am totally confused
gcc 4.4.3 c89 I am just getting started with log4c. However, there is very
gcc 4.4.4 c89 However, I am having a problem trying to display all the
gcc 4.4.3 c89 pthreads I use valgrind for checking memory errors. I am just
gcc 4.4.2 c89 I have a wave file: 8000 Hz 16 bit I am

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.