[so] [Tema1][General] Conversie string - long

Bogdan Oprea oprea.bg at gmail.com
Sun Mar 13 20:01:59 EET 2016


Salut,

Eu citesc intrarea ca un string pe care apoi il parsez. Pentru situatiile
in care am nevoie de conversie string - long int folosesc

*strtol.*
Problema mea ar fi ca nu imi dau seama exact cum as putea trata o eroare in
urma strtol. In documentatie am gasit urmatoarea explicatie:





*"On success, the function returns the converted integral number as a long
int value. If no valid conversion could be performed, a zero value is
returned (0L). If the value read is out of the range of representable
values by a long int, the function returns LONG_MAX or LONG_MIN (defined in
<climits> <http://www.cplusplus.com/climits>), and errno
<http://www.cplusplus.com/errno> is set to ERANGE."*
Initial m-am folosit de faptul ca intoarce 0 daca nu poate face conversie.
Doar ca pentru print_bucket pot avea ca indice si 0 caz in care valoarea
returnata de strtol nu o pot trata ca pe o eroare. Din cate inteleg *errno*
este setat doar daca valoarea este out of range, deci nu vad cum m-as
folosi de asta.

Mersi fain,
Bogdan


*George Bogdan Oprea*
Faculty of Automatic Control and Computers
University POLITEHNICA of Bucharest

e-mail:oprea.bg at gmail.com
telephone: +40 747 042 805
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cursuri.cs.pub.ro/pipermail/so/attachments/20160313/6efa2131/attachment.html>


More information about the so mailing list