December 09, 2005
Hi all

I'm trying to write a sudoku puzzle solver in D, but printf() starts printing mostly wrong characters and acting very erratically halfway through the program. I stuck in print statements to find where exactly in the code the problem was starting, and it happens in the middle of this loop:

for(i=0;i<9;i++)
{
for(j=0;j<9;j++)
{
for(k=0;k<10;k++)
{
poss[i][j][k]=1;
}
}
}

poss[9][9][10] is of type bit, does this have anything to do with it?  Any help is very much appreciated.  Thanks,

John


December 09, 2005
Try using writef instead of printf. How are you calling printf anyway ? Does it work when you change the array type from bit to int ?


john wrote:
> I'm trying to write a sudoku puzzle solver in D, but printf() starts printing
> mostly wrong characters and acting very erratically halfway through the program.
> I stuck in print statements to find where exactly in the code the problem was
> starting, and it happens in the middle of this loop:


-- 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M d-pu s+: a-->----- C+++$>++++ UL P+ L+ E--- W++ N++ o? K? w++ !O !M V? PS- PE- Y PGP t 5 X? R tv-- b DI- D+ G e>+++ h>++ !r !y
------END GEEK CODE BLOCK------

Tomasz Stachowiak  /+ a.k.a. h3r3tic +/
December 09, 2005
john schrieb:

> Hi all
> 
> I'm trying to write a sudoku puzzle solver in D, but printf() starts printing mostly wrong characters and acting very erratically halfway through the program. I stuck in print statements to find where exactly in the code the problem was starting, and it happens in the middle of this loop:
> 
> for(i=0;i<9;i++)
> {
> for(j=0;j<9;j++)
> {
> for(k=0;k<10;k++)
> {
> poss[i][j][k]=1;
> }
> }
> }
> 
> poss[9][9][10] is of type bit, does this have anything to do with it?  Any
> help
> is very much appreciated.  Thanks,
> 
> John

Hmmm.... don't see any printf() statement there...
What do you mean it behaves erratically? Can you give an example?
Please be aware that printf() is from the standard-C library and should be used with carefull!
Namely you should be carefull which parameters (type) you pass to it!
Have you tried writef()?

Tiago

-- 
Tiago Gasiba (M.Sc.) - http://www.gasiba.de
Everything should be made as simple as possible, but not simpler.
December 09, 2005
In article <dnbjct$gdr$1@digitaldaemon.com>, Tiago Gasiba says...
>
>john schrieb:
>
>> Hi all
>> 
>> I'm trying to write a sudoku puzzle solver in D, but printf() starts printing mostly wrong characters and acting very erratically halfway through the program. I stuck in print statements to find where exactly in the code the problem was starting, and it happens in the middle of this loop:
>> 
>> for(i=0;i<9;i++)
>> {
>> for(j=0;j<9;j++)
>> {
>> for(k=0;k<10;k++)
>> {
>> poss[i][j][k]=1;
>> }
>> }
>> }
>> 
>> poss[9][9][10] is of type bit, does this have anything to do with it?  Any
>> help
>> is very much appreciated.  Thanks,
>> 
>> John
>
>Hmmm.... don't see any printf() statement there...
>What do you mean it behaves erratically? Can you give an example?
>Please be aware that printf() is from the standard-C library and should be used with carefull!
>Namely you should be carefull which parameters (type) you pass to it!
>Have you tried writef()?
>
>Tiago
>
>-- 
>Tiago Gasiba (M.Sc.) - http://www.gasiba.de
>Everything should be made as simple as possible, but not simpler.



There isn't any printing going on in that loop...printf worked before the loop and fails during the loop.  I tried printing within the loop and halfway through it fouled up.  Afterwards, printf is printing some correct characters but mostly randomness from the extended ASCII codes.  Does the writef syntax mimic that of printf?  How is it different?


December 09, 2005
Uh.... Making a sudoku solver by any chance??? (me too!)

L.


December 09, 2005
Sorry, I only saw the code, didn't see you actually mention making the solver.. The code was _so_ familiar, since I'm working on exactly the same thing RIGHT NOW!  I was so shocked that I replied immediately..

L.


December 09, 2005
john schrieb:

> In article <dnbjct$gdr$1@digitaldaemon.com>, Tiago Gasiba says...
>>
>>john schrieb:
>>
>>> Hi all
>>> 
>>> I'm trying to write a sudoku puzzle solver in D, but printf() starts printing mostly wrong characters and acting very erratically halfway through the program. I stuck in print statements to find where exactly in the code the problem was starting, and it happens in the middle of this loop:
>>> 
>>> for(i=0;i<9;i++)
>>> {
>>> for(j=0;j<9;j++)
>>> {
>>> for(k=0;k<10;k++)
>>> {
>>> poss[i][j][k]=1;
>>> }
>>> }
>>> }
>>> 
>>> poss[9][9][10] is of type bit, does this have anything to do with it?
>>> Any help
>>> is very much appreciated.  Thanks,
>>> 
>>> John
>>
>>Hmmm.... don't see any printf() statement there...
>>What do you mean it behaves erratically? Can you give an example?
>>Please be aware that printf() is from the standard-C library and should be
>>used with carefull! Namely you should be carefull which parameters (type)
>>you pass to it! Have you tried writef()?
>>
>>Tiago
>>
>>--
>>Tiago Gasiba (M.Sc.) - http://www.gasiba.de
>>Everything should be made as simple as possible, but not simpler.
> 
> 
> 
> There isn't any printing going on in that loop...printf worked before the
> loop
> and fails during the loop.  I tried printing within the loop and halfway
> through
> it fouled up.  Afterwards, printf is printing some correct characters but
> mostly
> randomness from the extended ASCII codes.  Does the writef syntax mimic
> that of
> printf?  How is it different?


writef() works very much like printf(). See this:
http://www.digitalmars.com/d/phobos/std_stdio.html

Without any reproducible code it's very difficult...
The following code works fine for me (bit is implicitly promoted to int).
<snip>
int main(){
  bit  poss[10][10][10];
  int  i,j,k;

  for(i=0;i<9;i++){
    for(j=0;j<9;j++){
      for(k=0;k<10;k++){
        poss[i][j][k]=1;
        printf("%d ",poss[i][j][k]);
      }
      printf("\n");
    }
  }
  return 0;
}
<snip>

Tiago

-- 
Tiago Gasiba (M.Sc.) - http://www.gasiba.de
Everything should be made as simple as possible, but not simpler.
December 09, 2005
In article <dnbm2l$mbs$1@digitaldaemon.com>, Tiago Gasiba says...
>
>john schrieb:
>
>> In article <dnbjct$gdr$1@digitaldaemon.com>, Tiago Gasiba says...
>>>
>>>john schrieb:
>>>
>>>> Hi all
>>>> 
>>>> I'm trying to write a sudoku puzzle solver in D, but printf() starts printing mostly wrong characters and acting very erratically halfway through the program. I stuck in print statements to find where exactly in the code the problem was starting, and it happens in the middle of this loop:
>>>> 
>>>> for(i=0;i<9;i++)
>>>> {
>>>> for(j=0;j<9;j++)
>>>> {
>>>> for(k=0;k<10;k++)
>>>> {
>>>> poss[i][j][k]=1;
>>>> }
>>>> }
>>>> }
>>>> 
>>>> poss[9][9][10] is of type bit, does this have anything to do with it?
>>>> Any help
>>>> is very much appreciated.  Thanks,
>>>> 
>>>> John
>>>
>>>Hmmm.... don't see any printf() statement there...
>>>What do you mean it behaves erratically? Can you give an example?
>>>Please be aware that printf() is from the standard-C library and should be
>>>used with carefull! Namely you should be carefull which parameters (type)
>>>you pass to it! Have you tried writef()?
>>>
>>>Tiago
>>>
>>>--
>>>Tiago Gasiba (M.Sc.) - http://www.gasiba.de
>>>Everything should be made as simple as possible, but not simpler.
>> 
>> 
>> 
>> There isn't any printing going on in that loop...printf worked before the
>> loop
>> and fails during the loop.  I tried printing within the loop and halfway
>> through
>> it fouled up.  Afterwards, printf is printing some correct characters but
>> mostly
>> randomness from the extended ASCII codes.  Does the writef syntax mimic
>> that of
>> printf?  How is it different?
>
>
>writef() works very much like printf(). See this:
>http://www.digitalmars.com/d/phobos/std_stdio.html
>
>Without any reproducible code it's very difficult...
>The following code works fine for me (bit is implicitly promoted to int).
><snip>
>int main(){
>  bit  poss[10][10][10];
>  int  i,j,k;
>
>  for(i=0;i<9;i++){
>    for(j=0;j<9;j++){
>      for(k=0;k<10;k++){
>        poss[i][j][k]=1;
>        printf("%d ",poss[i][j][k]);
>      }
>      printf("\n");
>    }
>  }
>  return 0;
>}
><snip>
>
>Tiago
>
>-- 
>Tiago Gasiba (M.Sc.) - http://www.gasiba.de
>Everything should be made as simple as possible, but not simpler.



Actually changing poss from bit to int made the problem stop.  I thought bit worked just like booleans in java, but something went awry.


December 09, 2005
In article <dnbm2l$mbs$1@digitaldaemon.com>, Tiago Gasiba says...
>
>john schrieb:
>
>> In article <dnbjct$gdr$1@digitaldaemon.com>, Tiago Gasiba says...
>>>
>>>john schrieb:
>>>
>>>> Hi all
>>>> 
>>>> I'm trying to write a sudoku puzzle solver in D, but printf() starts printing mostly wrong characters and acting very erratically halfway through the program. I stuck in print statements to find where exactly in the code the problem was starting, and it happens in the middle of this loop:
>>>> 
>>>> for(i=0;i<9;i++)
>>>> {
>>>> for(j=0;j<9;j++)
>>>> {
>>>> for(k=0;k<10;k++)
>>>> {
>>>> poss[i][j][k]=1;
>>>> }
>>>> }
>>>> }
>>>> 
>>>> poss[9][9][10] is of type bit, does this have anything to do with it?
>>>> Any help
>>>> is very much appreciated.  Thanks,
>>>> 
>>>> John
>>>
>>>Hmmm.... don't see any printf() statement there...
>>>What do you mean it behaves erratically? Can you give an example?
>>>Please be aware that printf() is from the standard-C library and should be
>>>used with carefull! Namely you should be carefull which parameters (type)
>>>you pass to it! Have you tried writef()?
>>>
>>>Tiago
>>>
>>>--
>>>Tiago Gasiba (M.Sc.) - http://www.gasiba.de
>>>Everything should be made as simple as possible, but not simpler.
>> 
>> 
>> 
>> There isn't any printing going on in that loop...printf worked before the
>> loop
>> and fails during the loop.  I tried printing within the loop and halfway
>> through
>> it fouled up.  Afterwards, printf is printing some correct characters but
>> mostly
>> randomness from the extended ASCII codes.  Does the writef syntax mimic
>> that of
>> printf?  How is it different?
>
>
>writef() works very much like printf(). See this:
>http://www.digitalmars.com/d/phobos/std_stdio.html
>
>Without any reproducible code it's very difficult...
>The following code works fine for me (bit is implicitly promoted to int).
><snip>
>int main(){
>  bit  poss[10][10][10];
>  int  i,j,k;
>
>  for(i=0;i<9;i++){
>    for(j=0;j<9;j++){
>      for(k=0;k<10;k++){
>        poss[i][j][k]=1;
>        printf("%d ",poss[i][j][k]);
>      }
>      printf("\n");
>    }
>  }
>  return 0;
>}
><snip>
>
>Tiago
>
>-- 
>Tiago Gasiba (M.Sc.) - http://www.gasiba.de
>Everything should be made as simple as possible, but not simpler.




I thought bit worked like boolean in java, but changing poss to type int solves the problem.  Thanks everybody.


December 09, 2005
john wrote:

> Actually changing poss from bit to int made the problem stop.  I thought bit
> worked just like booleans in java, but something went awry.  

bit works more like _Bool does in C. :-P Except a little bit worse...

It (booleans) and strings are the biggest problems for newcomers to D.

--anders
« First   ‹ Prev
1 2 3
Top | Discussion index | About this forum | D home