Hi,
I don't currently use C#, so I'm not sure as to the 'safeness' of it. From
what little I know, unsafe blocks are required for anything using pointers,
which is what sprintf does, so it should be ok. From memory, the sprintf
syntax is 'sprintf ( char* buffer, const char* format ), so the following
code prints a couple of numbers as octals:
char buffer[50];
int a = 10, b = 5;
int usedBufferSize = ( buffer, "In octal, a = %o and b = %o", a, b );
usedBufferSize then contains the number of used chars in buffer.
Play around with it, you should be able to get it to work but as I say, I'm
not a C# programmer so there may be issues I'm unaware of.
HTH,
Steve
"Steven Livingstone" <s.***********@nospam.btinternet.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi Steve - is it possible to call sprintf in an unsafe block in C#??
If so do you have an example? I looked all over the place, but my lack of
C++ knowledge if likely the cause of finding nothing that showd it
actually working!
"Steve McLellan" <sj*@fixerlabs.com.NOSPAM> wrote in message
news:#2**************@tk2msftngp13.phx.gbl... Hi,
Don't know whether or not there's a C# alternative, but it seems likely
there should be. In any case, sprintf (rather than printf) is probably
the C function to do what you want - it prints into a buffer you give it.
Steve
"Steven Livingstone" <s.***********@nospam.btinternet.com> wrote in message news:uk****************@TK2MSFTNGP12.phx.gbl... If I was using C# and wanted to call the printf function what would I
do?
Specifically i want to convert a string to octal and as there is no
facility for doing this in C# i figured i'd look at using C++. Even better
would be a function that returns me a string or char array to C# when i call C++ rather than printing it out.
I can get it working by calling VB from C#, but with C++ i am finding
it a little tricky!
Psuedocode below....
static void Main(string[] args)
{
char[] instr = Console.ReadLine().ToCharArray();
char[] outstr;
unsafe
{
outstr = ConvertToOctalHere(instr);
}
Console.WriteLine(outstr);
Console.ReadLine();
}
thanks,
Steven.