Need to skip newline char (\n) from input file

Posted by igor on Stack Overflow See other posts from Stack Overflow or by igor
Published on 2010-04-01T00:34:09Z Indexed on 2010/04/01 0:43 UTC
Read the original article Hit count: 367

Filed under:
|
|
|

I am reading in a file into an array. It is reading each char, the problem arises in that it also reads a newline in the text file.

This is a sudoku board, here is my code for reading in the char:

bool loadBoard(Square board[BOARD_SIZE][BOARD_SIZE])
{
 ifstream ins;

 if(openFile(ins)){


 char c;

 while(!ins.eof()){
 for (int index1 = 0; index1 < BOARD_SIZE; index1++)
  for (int index2 = 0; index2 < BOARD_SIZE; index2++){ 
   c=ins.get();

   if(isdigit(c)){
   board[index1][index2].number=(int)(c-'0');
   board[index1][index2].permanent=true;
   }
  }
    }

 return true;}
 return false;
}

like i said, it reads the file, displays on screen, just not in correct order when it encounters the \n

© Stack Overflow or respective owner

Related posts about c++

Related posts about sudoku

  • Do you play Sudoku ?

    as seen on Oracle Blogs - Search for 'Oracle Blogs'
    Did you know that 11gR2 database could solve a Sudoku puzzle with a single query and, most of the time, and this in less than a second ? The following query shows you how ! Simply pass a flattened Sudoku grid to it a get the result instantaneously ! col "Solution" format a9 … >>> More

  • Python sudoku programming

    as seen on Stack Overflow - Search for 'Stack Overflow'
    I need your help on this. I have this program and I must finish it. It's missing 3 parts. Here is the program I'm working with: import copy def display(A): if A: for i in range(9): for j in range(9): if type(A[i][j]) == type([]): print A[i][j][0], … >>> More

  • Sudoku solver evaluation function

    as seen on Stack Overflow - Search for 'Stack Overflow'
    Hi, So I'm trying to write a simple genetic algorithm for solving a sudoku (not the most efficient way, I know, but it's just to practice evolutionary algorithms). I'm having some problems coming up with an efficient evaluation function to test if the puzzle is solved or not and how many errors there… >>> More

  • Solving Naked Triples in Sudoku

    as seen on Stack Overflow - Search for 'Stack Overflow'
    Hello, I wished I paid more attention to the math classes back in Uni. :) How do I implement this math formula for naked triples? Naked Triples Take three cells C = {c1, c2, c3} that share a unit U. Take three numbers N = {n1, n2, n3}. If each cell in C has as its candidates ci ? N then we can… >>> More

  • Sudoku Solver

    as seen on SQL Blog - Search for 'SQL Blog'
    Today I am putting up something silly, just for fun. I set myself the task a while back to write a Sudoku solver in T-SQL, but with two dumb constraints that I would never follow given a real problem: I didn’t look at any documented techniques for solving Sudoku, and I specifically avoided T-SQL solutions… >>> More