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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:58:32+00:00 2026-06-12T10:58:32+00:00

I am making a Sudoku program and my i have a test.txt file that

  • 0

I am making a Sudoku program and my i have a test.txt file that reads

53__7____    
6__195___
_98____6_
8___6___3
4__8_3__1
7___2___6
_6____28_
___419__5
____8__79

where the “_” are actually spaces. The reason i give you _ is so you can see that there are literally only 9 characters on each line.

I was thinking that I would have to do something like having GRID[row][column], however I frankly don’t know what types I should put my arrays as and I am just lost.

I simply want to make it so when i want to output say GRID[0][0] it returns 5, while if i ask for GRID[0][3] it returns a ‘ ‘.

It is getting it so the array store both the numbers and the spaces is where i am getting completely lost

What I currently have tried so far:

int main()
{
 ifstream myfile(test.txt);
 string line;
 char sudoku_grid[9][9];

 if (myfile.is_open())
 {
  while(myfile.good())
   {
    getline(myfile, line);
    cout << sudoku_grid[line] << endl;
   }
   myfile.close();
  }
 else cout << "error";
 return 0;
}

it returns the error line 12: no match for ‘operator [ ]’ in ‘sudoku_grid[line]’

Here is my attempt though guidelines through you guys:

int main()
{
 ifstream myfile(test.txt);
 string line;
 char sudoku_grid[9][9];

 if (myfile.good())
 {
  for(int i = 0; i < 9; i++)
   {
    getline(myfile, line);
    for(int j = 0; j < 9; j++)
       {
       if (line[j] == ' ')
          sudoku_grid[j][i] = -1;
       else  sudoku_grid[j][i] = line[i];
       }
    cout << sudoku_grid[i] << endl;
   }
   myfile.close();
  }
 else cout << "error";
 return 0;
}

The result is a very awkward answer of strange letters and a new numbers.

  • 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-12T10:58:33+00:00Added an answer on June 12, 2026 at 10:58 am

    Since you need to store both chars and integer type values, use char. each of your integer lies in the range 0-9, so can be stored as a character.

    char Grid[9][9];
    

    now you can read each character from the string and store it in the array. It will not only keep your spaces intact but also each character. Always remember to use ASCII codes to access the elements of the grid. For 0-9, ASCII codes are 48-57, ASCII code for space is 32.

    Hope it helps…

    Edit code: Here is the simplest example… PLace your test file in d:, or edit the path of file in code

    int main (void)
    {
        FILE    *fp = fopen("d:\\test.txt","r");
        char sudoku_grid[9][9], ch;
        // I am assuming that file is valid and data in that is also valid
        if(fp)
        {
            for(int i = 0; i < 9; i++)
            {            
                for(int j = 0; j < 9; j++)
                {
                    //too read each character
                    ch = fgetc(fp);
                    sudoku_grid[i][j] = ch;   
                }
                // to read '\n' from the line
                ch = fgetc(fp);
            }
    //for checking if data went correctly
            for(int i = 0; i< 9;i++)
            {
                for(int j= 0; j<9;j++)
                    cout<<sudoku_grid[i][j];
                cout<<endl;
            }
        }
    
    
     return 0; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Making a small WCF test program which is based on a Store that has
I'm making a Sudoku program in java to learn some algorithms so I want
I was thinking of making a Sudoku solver, I have 2 questions: 1) What
Making a simple program which will generate a multiple choice form. I have an
Making game of life I need to a have a grid that is 30x20
Making a ship game because I am incredibly original.. With that aside, I have
im making an application where i have to load my database from html file
The program above is, as said, a Sudoku game. I have written down ideas
Making a word document of our network set-up. We have about 7 servers and
Making an adobe flex ui in which data that is calculated must use proprietary

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.