Search
printf() problems
Dec 09, 2005
john
Dec 09, 2005
Tom S
Dec 09, 2005
Tiago Gasiba
Dec 09, 2005
john
Dec 09, 2005
Tiago Gasiba
Dec 09, 2005
john
Dec 12, 2005
Tiago Gasiba
Dec 09, 2005
john
Dec 09, 2005
Lionello Lunesu
Dec 09, 2005
Lionello Lunesu
Dec 12, 2005
Stewart Gordon
Dec 12, 2005
Tiago Gasiba
Dec 12, 2005
Tiago Gasiba
Dec 12, 2005
Stewart Gordon
Dec 12, 2005
Oskar Linde
Dec 12, 2005
Tiago Gasiba
Sudoku solving (was: printf() problems)
Dec 13, 2005
Stewart Gordon
Dec 13, 2005
Tiago Gasiba
Dec 13, 2005
Tiago Gasiba
Re: Sudoku solving
Dec 15, 2005
Stewart Gordon
Dec 16, 2005
Lionello Lunesu
Dec 16, 2005
Stewart Gordon
Dec 16, 2005
Lionello Lunesu
Dec 16, 2005
Stewart Gordon
Dec 16, 2005
Lionello Lunesu
```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

```
```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 +/
```
```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.
```
```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?

```
```Uh.... Making a sudoku solver by any chance??? (me too!)

L.

```
```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.

```
```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.
```
```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.

```
```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.

```
```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