Jump to content

printf()


xerox
 Share

Recommended Posts

I am trying to use printf() but it doesn't seem to work correctly?

#AutoIt3Wrapper_Change2CUI=y
#AutoIt3Wrapper_UseX64=y

#pragma compile(Console, true)
$float1 = 0.9375
$float2 = 0.9375
DllCall("msvcrt.dll", "int:cdecl", "printf", "str", "Floats: %10.3f, %10.3f", "ptr", $float1, "ptr", $float2)

ConsoleRead();

Result:

"Floats:      0.000,      0.000"

 

Edited by xerox
Link to comment
Share on other sites

Why not use StringFormat?

Local $float1 = 0.9375
Local $float2 = 0.9375

Local $formatedText = StringFormat("Floats: %10.3f, %10.3f", $float1, $float2)
ConsoleWrite($formatedText & @CRLF)

 

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

Take a lookk on this topic to learn how to get the variable pointer and use the pointers (instead of native AutoIt variables) in your DllCall: https://www.autoitscript.com/forum/topic/180644-get-the-actual-true-pointer-for-an-autoit-native-variable-updated/

My stuff

Spoiler

My UDFs  _AuThread multithreading emulation for AutoIt · _ExtInputBox an inputbox with multiple inputs and more features · forceUTF8 fix strings encoding without knowing its original charset · JSONgen JSON generator · _TCPServer UDF multi-client and multi-task (run on background) event-based TCP server easy to do · _TCPClient_UDF multi-server and multi-task (runs on background) event-based TCP client easy to do · ParseURL and ParseStr functions ported from PHP · _CmdLine UDF easily parse command line parameters, keys or flags · AutoPHP Create documents (bills, incomes) from HTML by sending variables/arrays from AutoIt to PHP · (Un)Serialize Convert arrays and data into a storable string (PHP compatible) · RTTL Plays and exports to MP3 Nokia-format monophonic ringtones (for very old cellphones) · I18n library Simple and easy to use localization library · Scripting.Dictionary OOP and OOP-like approach · Buffer/stack limit arrays to N items by removing the last one once the limit is reached · NGBioAPI UDF to work with Nitgen fingerprint readers · Serial/Licensing system require license key based on unique machine ID from your users · HTTP a simple WinHTTP library that allows GET, POST and file uploads · Thread true AutoIt threads (under-dev) · RC4 RC4 encryption compatible with PHP and JS ·  storage.au3 localStorage and sessionStorage for AutoIt Classes _WKHtmlToX uses wkhtmlto* to convert HTML files and webpages into PDF or images (jpg, bmp, gif, png...) Snippets _Word_DocFindReplaceByLongText replace strings using Word UDF with strings longer than 255 characters (MSWord limit) rangeparser parser for printing-like pages interval (e.g.: "1,2,3-5") EnvParser parse strings/paths with environment variables and get full path GUICtrlStaticMarquee static text scrolling Random stuff Super Mario beep sound your ears will hurt

 

Link to comment
Share on other sites

You could still use native AutoIt variables with the printf function, but using StringFormat is better and easier i think.

 

Local $float1 = 0.9375
Local $float2 = 0.9375
Local $string = "Hello" & @CRLF

Local $formatedText = StringFormat("Native: %10.3f, %10.3f", $float1, $float2)
ConsoleWrite($formatedText & @CRLF)

DllCall("msvcrt.dll", "int:cdecl", "printf", "str", "Printf: %10.3lf, %10.3f - %s", "double", $float1, "double", $float2, "str", $string)

ConsoleRead();

 

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...