Last active
October 15, 2017 16:22
-
-
Save Archie-Yang/f794873f1ec03c8abc92a59a0ab67133 to your computer and use it in GitHub Desktop.
sscanf (msvcrt40.dll)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Runtime.InteropServices; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
[DllImport("msvcrt40.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] | |
public static extern int sscanf(string str, string format, __arglist); | |
static void Main(string[] args) | |
{ | |
var enc = Encoding.Default; | |
var buf1 = new byte[100]; | |
var buf2 = new byte[100]; | |
int int1, int2; | |
Console.WriteLine(sscanf("hello world! 123456789 987654321", "%s %s %d %d", __arglist(buf1, buf2, out int1, out int2))); | |
Console.WriteLine(enc.GetString(buf1, 0, Array.IndexOf(buf1, (byte)0))); // hello | |
Console.WriteLine(enc.GetString(buf2, 0, Array.IndexOf(buf2, (byte)0))); // world! | |
Console.WriteLine(int1); // 123456789 | |
Console.WriteLine(int2); // 987654321 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment