www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - problems printing a dchar

reply Orgoton <orgoton mindless.com> writes:
this code will result on a win32 exception when trying to writefln "nomeEnt"

import std.stdio;
import std.intrinsic;
import std.stream;
import std.string;

int main()
{
    ushort tamanho;
    ubyte[] buffer1, buffer2;
    dchar[255] nomeEnt='\0', nomeSai;
    writef("Introduza o tamanho da matrix de encriptacao: ");
    scanf("%d", &tamanho);
    buffer1.length=tamanho*tamanho;
    buffer2.length=tamanho*tamanho;
    writef("Introduza o nome do ficheiro a encriptar: ");
    scanf("%s", &nomeEnt);
    writef("Abrindo " );
    getch();
    writefln(nomeEnt);
    //File fichEnt=new File(nomeEnt, FileMode.In);
    //buffer1.length=0;
    //buffer2.length=0;
    return 0;
}

Also, changing "dchar" to "char" will print the string, but will also cause the
program to throw "invalid UTF-8 sequence. Suggestions?
Feb 25 2007
parent torhu <fake address.dude> writes:
Orgoton wrote:
 this code will result on a win32 exception when trying to writefln "nomeEnt"
 
 import std.stdio;
 import std.intrinsic;
 import std.stream;
 import std.string;
 
 int main()
 {
     ushort tamanho;
     ubyte[] buffer1, buffer2;
     dchar[255] nomeEnt='\0', nomeSai;
     writef("Introduza o tamanho da matrix de encriptacao: ");
     scanf("%d", &tamanho);
     buffer1.length=tamanho*tamanho;
     buffer2.length=tamanho*tamanho;
     writef("Introduza o nome do ficheiro a encriptar: ");
     scanf("%s", &nomeEnt);
     writef("Abrindo " );
     getch();
     writefln(nomeEnt);
     //File fichEnt=new File(nomeEnt, FileMode.In);
     //buffer1.length=0;
     //buffer2.length=0;
     return 0;
 }
 
 Also, changing "dchar" to "char" will print the string, but will also cause
the program to throw "invalid UTF-8 sequence. Suggestions?
scanf doesn't work with utf-32. Try looking at std.cstream instead.
Feb 25 2007