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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:25:43+00:00 2026-06-13T08:25:43+00:00

My title is a bit confusing, but I’m trying to write a loop that

  • 0

My title is a bit confusing, but I’m trying to write a loop that will change the value in 81 arrays with different names. I want to either initiated the array with a value or an array of values. This is part of my sudoku solver code since I don’t think I’m explaining it well.

int cell1[], cell2[9], cell3[9],cell4[9]......cell81[9]; // <-- this will make 81 cells with an array that can hold a possible of 9 candidates

cout << "User input: << endl; // lets use ...1.5...14....67..8...24...63.7..1.9.......3.1..9.52...72...8..26....35...4.9...
                              // as an example

Let’s assume I store that input into a Char Array and I’m going to use a loop to decide whether to initiate the given value or ‘.’ as an empty value.

For empty values, I’m looking to initialize the array with 1-9 values. I can do this easily with this code.

If( ( (int)charArray[ 0 ] - 48) > 0 ) {   // type cast to int. Neg = initialize array with 1-9
                                         // pos = initialize with original value

cell1[ 0 ] =  (int)charArray[ 0 ] - 48;
} else {

cell1[ 9 ] = { 1,2,3,4,5,6,7,8,9};
}

I want to avoid writing this code 81 times for 81 cells ( Considered as writing junk code ). I can’t figure out how to write the loop. I’m open to suggestions on how I can code this different using classes, functions, and etc. Thanks in advance.

  • 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-13T08:25:44+00:00Added an answer on June 13, 2026 at 8:25 am

    Create the cell array as a 2-dimensional array, with 81 rows and 9 columns.

    int cell[81][9];
    

    Now you can loop through them using the syntax cell[r][c]. For instance,

    for( i = 0; i < 81; ++i ) {
      cell[i][0] = 1;
      // ...
      cell[i][8] = 9;
    }
    

    If you’d prefer to avoid 2-D arrays, you can declare the array as a 1-dimensional array, and just index into it appropriately.

    int cell[81 * 9];
    
    for( i = 0; i < 81; ++i ) {
      cell[i + 0*81] = 1;
      // ...
      cell[i + 8*81] = 9;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That title is a mouthful and a bit confusing, but you are still reading
The title might be a bit confusing, basically I'm trying to write up a
I'll admit the title is a bit confusing but it was hard to come
Ok, the title is a bit confusing, but here's my predicament. I've made a
The title may be bit confusing but here is what I am facing I
The title is a bit confusing but here's what I'm after: I have a
The title might have been a bit confusing but I can clarify here. I'm
I know the title of this question is a bit confusing, but here it
OK, the title is a bit(lot) cryptic, but that's the best one-line-summary I could
Ok I know the title is a bit confusing but here is my problem:

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.