www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript
electronics



digitalmars.D - problems printing a dchar

↑ ↓ ← 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
↑ ↓ → 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