Thread overview
Erratic printf and writef behavior
Feb 01, 2006
john C
Feb 01, 2006
Derek Parnell
Feb 01, 2006
MicroWizard
February 01, 2006
Hi All

I'm new to the D language and I'm running into really confounding problems with my sudoku solver.  Here's the part of my program where writef and printf stop working:

void reduce_possibilities(char puz[9][9],bit poss[9][9][10])
{
int i,j,k;

writefln("reduce possiblilities called");
for(i=0;i<9;i++)   //printf() stops working in this loop!
{
for(j=0;j<9;j++)
{
for(k=0;k<10;k++)
{
poss[i][j][k]=1;
}
}
}
writefln("test");
for(i=0;i<9;i++)
{
for(j=0;j<9;j++)
{
if(puz[i][j]!='0')
{
reduce_known(poss,i,j,(cast(int)(puz[i][j]))-48);
reduce_column(poss,i,j,(cast(int)(puz[i][j]))-48);
reduce_row(poss,i,j,(cast(int)(puz[i][j]))-48);
reduce_block(poss,i,j,(cast(int)(puz[i][j]))-48);
}
}
}
writefln("leaving reduce possiblities method");
}




The program prints the method called message, but in the following loops the io gets messed up somehow (the "test" message does not print).  Instead, the program prints mostly white space and some funny characters ie smiley face, spade, etc, then it prints an error message which says "Error: 4invalid UTF-8 sequence".  Can anybody help me out here?  D isn't much use to me if the print statements aren't reliable, but I would love to keep working with it.  Can anyone help me out?  Thanks

John C


February 01, 2006
On Wed, 1 Feb 2006 05:02:21 +0000 (UTC), john C wrote:

> Hi All
> 
> I'm new to the D language and I'm running into really confounding problems with my sudoku solver.  Here's the part of my program where writef and printf stop working:
> 
> void reduce_possibilities(char puz[9][9],bit poss[9][9][10])
> {
> int i,j,k;
> 
> writefln("reduce possiblilities called");
> for(i=0;i<9;i++)   //printf() stops working in this loop!
> {
> for(j=0;j<9;j++)
> {
> for(k=0;k<10;k++)
> {
> poss[i][j][k]=1;
> }
> }
> }
> writefln("test");
> for(i=0;i<9;i++)
> {
> for(j=0;j<9;j++)
> {
> if(puz[i][j]!='0')
> {
> reduce_known(poss,i,j,(cast(int)(puz[i][j]))-48);
> reduce_column(poss,i,j,(cast(int)(puz[i][j]))-48);
> reduce_row(poss,i,j,(cast(int)(puz[i][j]))-48);
> reduce_block(poss,i,j,(cast(int)(puz[i][j]))-48);
> }
> }
> }
> writefln("leaving reduce possiblities method");
> }
> 
> The program prints the method called message, but in the following loops the io gets messed up somehow (the "test" message does not print).  Instead, the program prints mostly white space and some funny characters ie smiley face, spade, etc, then it prints an error message which says "Error: 4invalid UTF-8 sequence".  Can anybody help me out here?  D isn't much use to me if the print statements aren't reliable, but I would love to keep working with it.  Can anyone help me out?  Thanks
> 
> John C

It sounds like you are trying to display characters in the ranges 0x00 - 0x1F. Are you mixing up the character '1' with the integer 1?

ASCII character '1' has the integer value of 49.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocracy!"
1/02/2006 4:52:50 PM
February 01, 2006
Please include real and complete source snippets,
but try to reduce it to the smallest size where
the problem is reproducible.

It sounds like you have mixed up printf's and writef's format specifiers.
When you use printf with D strings and "%s" it will show garbage since
D strings are not terminated with 0.
With printf and D string you have to specify "%.*s"
When you use writef, the "%s" has different meaning but it should work.

Tamás Nagy
MicroWizard

In article <drpfct$2q1f$1@digitaldaemon.com>, john C says...
>
>Hi All
>
>I'm new to the D language and I'm running into really confounding problems with my sudoku solver.  Here's the part of my program where writef and printf stop working:
>
>void reduce_possibilities(char puz[9][9],bit poss[9][9][10])
>{
>int i,j,k;
>
>writefln("reduce possiblilities called");
>for(i=0;i<9;i++)   //printf() stops working in this loop!
>{
>for(j=0;j<9;j++)
>{
>for(k=0;k<10;k++)
>{
>poss[i][j][k]=1;
>}
>}
>}
>writefln("test");
>for(i=0;i<9;i++)
>{
>for(j=0;j<9;j++)
>{
>if(puz[i][j]!='0')
>{
>reduce_known(poss,i,j,(cast(int)(puz[i][j]))-48);
>reduce_column(poss,i,j,(cast(int)(puz[i][j]))-48);
>reduce_row(poss,i,j,(cast(int)(puz[i][j]))-48);
>reduce_block(poss,i,j,(cast(int)(puz[i][j]))-48);
>}
>}
>}
>writefln("leaving reduce possiblities method");
>}
>
>
>
>
>The program prints the method called message, but in the following loops the io gets messed up somehow (the "test" message does not print).  Instead, the program prints mostly white space and some funny characters ie smiley face, spade, etc, then it prints an error message which says "Error: 4invalid UTF-8 sequence".  Can anybody help me out here?  D isn't much use to me if the print statements aren't reliable, but I would love to keep working with it.  Can anyone help me out?  Thanks
>
>John C
>
>