digitalmars.D - Simple, but how?
- schnu (8/8) Feb 15 2005 Hello,
- Chris Sauls (8/21) Feb 15 2005 It looks to me like your error (Access Violation) is probably in the
- schnu (6/27) Feb 15 2005 Thank you, Chris. Your assumption was correct. I tried to use 'c' outsid...
- Chris Sauls (4/11) Feb 15 2005 Quite welcome. Its a fairly common beginner's mistake. :) Hell, I still...
- Regan Heath (7/26) Feb 15 2005 Or, it could be the printf
- Chris Sauls (5/6) Feb 15 2005 True enough, I missed that from the original post. Another good reason
- Walter (5/10) Feb 16 2005 short
- Chris Sauls (6/8) Feb 16 2005 I keep forgetting about format()...
Hello, I'm new to D programming and tried to convert an int to a char[]. Using str.string.toString() led to an access violation. I also didn't find those short c style conversion functions (like atoi etc.). Is there a way to do this conversion? The code that results in an error is: char[] s=std.string.toString((cast(TreeNode)c).text.length); printf(info~s);
Feb 15 2005
It looks to me like your error (Access Violation) is probably in the expression 'cast(TreeNode)c' and has nothing to do with std.string.toString() at all. Is 'c' a valid instance, assuming TreeNode is a class? Did you test with a dummy statement, something like 'char[] dummy = std.string.toString(1234);' ? And if you want 'atoi()' et al, just import std.conv and there you are. -- Chris S schnu wrote:Hello, I'm new to D programming and tried to convert an int to a char[]. Using str.string.toString() led to an access violation. I also didn't find those short c style conversion functions (like atoi etc.). Is there a way to do this conversion? The code that results in an error is: char[] s=std.string.toString((cast(TreeNode)c).text.length); printf(info~s);
Feb 15 2005
Thank you, Chris. Your assumption was correct. I tried to use 'c' outside my main loop (where c was checked). And also thanks for your hints. They will probably help me a lot. Regards, schnu In article <cuteqo$13fn$1 digitaldaemon.com>, Chris Sauls says...It looks to me like your error (Access Violation) is probably in the expression 'cast(TreeNode)c' and has nothing to do with std.string.toString() at all. Is 'c' a valid instance, assuming TreeNode is a class? Did you test with a dummy statement, something like 'char[] dummy = std.string.toString(1234);' ? And if you want 'atoi()' et al, just import std.conv and there you are. -- Chris S schnu wrote:Hello, I'm new to D programming and tried to convert an int to a char[]. Using str.string.toString() led to an access violation. I also didn't find those short c style conversion functions (like atoi etc.). Is there a way to do this conversion? The code that results in an error is: char[] s=std.string.toString((cast(TreeNode)c).text.length); printf(info~s);
Feb 15 2005
Quite welcome. Its a fairly common beginner's mistake. :) Hell, I still do it now and then, sadly/admittedly. -- Chris S schnu wrote:Thank you, Chris. Your assumption was correct. I tried to use 'c' outside my main loop (where c was checked). And also thanks for your hints. They will probably help me a lot. Regards, schnu
Feb 15 2005
On Tue, 15 Feb 2005 12:33:57 -0600, Chris Sauls <ibisbasenji gmail.com> wrote:It looks to me like your error (Access Violation) is probably in the expression 'cast(TreeNode)c' and has nothing to do with std.string.toString() at all.Or, it could be the printf printf(info~s); isn't a null terminated C string, it's a char * to a D string which is not null terminated. ReganIs 'c' a valid instance, assuming TreeNode is a class? Did you test with a dummy statement, something like 'char[] dummy = std.string.toString(1234);' ? And if you want 'atoi()' et al, just import std.conv and there you are. -- Chris S schnu wrote:Hello, I'm new to D programming and tried to convert an int to a char[]. Using str.string.toString() led to an access violation. I also didn't find those short c style conversion functions (like atoi etc.). Is there a way to do this conversion? The code that results in an error is: char[] s=std.string.toString((cast(TreeNode)c).text.length); printf(info~s);
Feb 15 2005
True enough, I missed that from the original post. Another good reason to use std.stdio.writef() instead of the (hopefully not for long) auto-imported printf. :) -- Chris S Regan Heath wrote:Or, it could be the printf
Feb 15 2005
"schnu" <schnu_member pathlink.com> wrote in message news:cuteag$134l$1 digitaldaemon.com...Hello, I'm new to D programming and tried to convert an int to a char[]. Using str.string.toString() led to an access violation. I also didn't find thoseshortc style conversion functions (like atoi etc.). Is there a way to do this conversion?std.string.format(i) will convert i to a string.
Feb 16 2005
I keep forgetting about format()... So on a side note, when will printf() get "cycled out" of D's default environment? I mean it was nice and all in the beginning, but now that we have std.stdio to use, is it really neccessary? -- Chris Sauls In article <cv0d3v$13dn$1 digitaldaemon.com>, Walter says...std.string.format(i) will convert i to a string.
Feb 16 2005