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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:54:56+00:00 2026-06-11T02:54:56+00:00

I’m trying to create a 2d grid using nested arrays of type int. Each

  • 0

I’m trying to create a 2d grid using nested arrays of type int. Each element in the grid will be set to a random value between -9 and 15. However, the integers that are being placed in the grid are being shown as their ASCII equivalent. Also, each element is the same random int, instead of being completely random. How can I fix these problems? Thanks for all your help!

#define ROWS 5
#define COLS 5

int main(void)
{

    int game_board[ROWS][COLS] = {0};
    initialize_game_board(game_board);
    display_board(game_board);
}

void initialize_game_board (int board[ROWS][COLS])
{

    int rows = 0, columns = 0, rand_int = 0;
    srand( time(NULL) );
    rand_int = (rand() % 24) - 9;

    for (rows = 0; rows < ROWS; rows++)
    {
        for (columns = 0; columns < COLS; columns++)
        {
            board[rows][columns] = rand_int;
        }
    }
}


void display_board(int board[ROWS][COLS])
{

    int row = 0, column = 0;

    printf ("\n%3d", row);
    for (row = 1; row < ROWS; row++)
    {
        printf ("%2d", row);
    }
    printf ("\n");

    for (row = 0; row < ROWS; row++)
    {
        printf ("%-2d", row);
        for (column = 0; column < COLS; column++)
        {
            printf ("%-2c", board[row][column]);
        }
        printf ("\n");
    }
}
  • 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-11T02:54:58+00:00Added an answer on June 11, 2026 at 2:54 am

    You declared game_board[ROWS][COLUMNS] as an integer array, and then when you use printf, you use %c.

    You can either declare it as a character array, and keep your %c (but then you have to change your function generate the ASCII characters for each number), or you can change the printf in the innermost loop of display_board to %d.

    Also, as a previous poster said, you only called random once and assigned it to all cells. Call random for each individual cell.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to select an H1 element which is the second-child in its group
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:

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.