Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c atoi() for wide chars on linux?

Tags:

c

linux

atoi

Is there a c atoi() equivalent for wide chars on Linux? I can find something for MS (wtoi) but I can find anything in a standard Linux lib.

like image 733
harrije Avatar asked Feb 21 '11 17:02

harrije


2 Answers

You can use wcstol to convert from wide strings to integer values.

like image 87
Reed Copsey Avatar answered Sep 25 '22 10:09

Reed Copsey


It is unusual for a Linux program to use wchar_t type.

The reason being that Linux uses utf-8 as the standard encoding. char const* strings are assumed to be utf-8 strings by glibc. Ascii digits and utf-8 digits have the same byte representation, so that atoi() works both on ascii and utf-8 strings.

Having said that, look in #include <wchar.t>, it provides wcstol().

like image 28
Maxim Egorushkin Avatar answered Sep 23 '22 10:09

Maxim Egorushkin