The problems:
Is there a free implementation of printf/sprintf for the .net framework? Other than the above link, I couldn't find anything.
Thanks!
Update:
Thanks for the help, even though you couldn't find anything. That means I'll just have to do it myself (I was trying to avoid it, but oh well...)
I cooked up a sprintf function that supports basic format strings, you can find it here: https://sourceforge.net/projects/printfnet/. I'll try to make it a complete implementation if I can.
Why don't you find a GPL-compatible implementation of printf
written in C and port it to .NET?
I think you want this: http://www.codeproject.com/KB/printing/PrintfImplementationinCS.aspx
It's a free implementation of a port of the C printf
function to C#. You should be aware the author points out that not all features of printf
are currently supported - but this may be a good starting point.
EDIT: I see that the license for that version isn't compatible with what you need - in that case, I definitely recommend looking at calling the unmanaged version directly as the following blog article discusses. It's probably the most compatible and safest thing to do.
If that doesn't cut it, here's a blog article about actually calling the unmanaged printf
function:
http://community.bartdesmet.net/blogs/bart/archive/2006/09/28/4473.aspx
It looks like this is all you need to call the unmanaged printf
from C#:
[DllImport("msvcrt40.dll")]
public static extern int printf(string format, __arglist);
static void Main(string[] args)
{
printf("Hello %s!\n", __arglist("Bart"));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With