atoi
converts a zero-terminated ASCII-String to an integer value.
Requires
#include "tiktag.h"
Definition
int atoi(const char *str);
Description
The atoi()
function is the tiktag implementation of the standard library function that stands for "ASCII to integer". It takes a string of characters as input and converts it to an integer value. The input string should contain only numerical characters (0-9), optionally preceded by a sign character (+ or -).
Parameters
char*
: zero terminated ASCII String that holds the number to be converted as a string.
Return Value
int
Remarks
-
Example: transmit a Javascript String to C++ Code and convert it to an integer
main.js:
import {_wasmInitA, _strToCPP} from "./tt/ttWASM.js";
import wasm from "./web.wasm";
async function main()
{
const wasmInstance = await _wasmInitA(wasm, {}, null);
wasmInstance.exports.printIntFromString (_strToCPP ("64738"));
}
main();
myCppExample.cpp:
#include "tiktag.h"
_export void printIntFromString(char* str)
{
int result = atoi (str);
consoleStr ("string in: ", str);
consoleNum ("converted Integer: ", result);
}
Output:
