C

atoi & strtol

Në shqip përdoret i njëjti emër.

ShpjegimiSQ

atoi("42") e kthen tekstin në numër, por s'të tregon nëse teksti ishte i gabuar ("abc" jep thjesht 0). strtol() është më i sigurt: të tregon ku ndaloi leximi, që ta dish nëse ishte numër i vlefshëm.

EnglishEN

atoi("42") turns text into a number, but doesn't tell you if the text was bad ("abc" just gives 0). strtol() is safer: it tells you where reading stopped, so you know whether it was a valid number.

Si ta mendosh

atoi është si sekretarja që shkruan 0 kur s'e lexon dorëshkrimin; strtol të thotë „s'e kuptova këtë pjesë“.

Lexoje në anglisht

atoi is like a clerk who writes 0 when they can't read the handwriting; strtol tells you “I couldn't read this part”.

Shembull kodic

char *fundi;
long n = strtol("42abc", &fundi, 10);
printf("%ld, mbeti: %s\n", n, fundi);   // 42, mbeti: abc

Terma të lidhur