digitalmars.D - Simple, but how?
- schnu <schnu_member pathlink.com> Feb 15 2005
- Chris Sauls <ibisbasenji gmail.com> Feb 15 2005
- schnu <schnu_member pathlink.com> Feb 15 2005
- Chris Sauls <ibisbasenji gmail.com> Feb 15 2005
- "Regan Heath" <regan netwin.co.nz> Feb 15 2005
- Chris Sauls <ibisbasenji gmail.com> Feb 15 2005
- "Walter" <newshound digitalmars.com> Feb 16 2005
- Chris Sauls <Chris_member pathlink.com> Feb 16 2005
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 those
c 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









Chris Sauls <ibisbasenji gmail.com> 