Scroll Down to See All
abortabsacosasctimeasctime_rasinassertatanatan2atexitatofatoibsearchbtowccalloccatclosecatgetscatopenceilclearerrclockcoscoshctimectime_rdifftimediverferfcexitexpfabsfclosefdopenfeofferrorfflushfgetcfgetposfgetsfgetwcfgetwsfopenfprintffputcfputwsfreadfreefreopenfrexpfscanffseekfsetposftellfwidefwprintffwritefwscanfgetcgetchargetenvgetwcgetwchargmtimegmtime_rhypotisalnumisalphaisasciiisblankiscntrlisdigitisgraphislowerisprintispunctisspaceisupperiswalnumiswalphaiswblankiswcntrliswctypeiswdigitiswgraphiswloweriswprintiswpunctiswspaceiswupperiswxdigitisxdigitj0j1jnlabsldexpldivlocaleconvlocaltimelocaltime_rloglog10longjmpmallocmblenmbrlenmbrtowcmbsinitmbsrtowcsmbstowcsmbtowcmemchrmemcmpmemcpymemmovememsetmktimemodfnextafternextafterlnexttowardnexttowardlnl_langinfoperrorpowprintfputcputcharputenvputsputwcputwcharqsortquantexpd32quantexpd64quantexpd128quantized32quantized64quantized128samequantumd32raiserandrand_rreallocregcompregerrorregexecregfreeremoverenamerewindscanfsetbufsetjmpsetlocalesetvbufsignalsinsinhsnprintfsprintfsqrtsrandsscanfstrcasecmpstrcatstrchrstrcmpstrcollstrcpystrcspnstrerrorstrfmonstrftimestrlenstrncasecmpstrncatstrncmpstrncpystrpbrkstrptimestrrchrstrspnstrstrstrtodstrtod32strtod64strtod128strtofstrtokstrtok_rstrtolstrtoldstrtoulstrxfrmswprintfswscanfsystemtantanhtimetime64tmpfiletmpnamtoasciitolowertouppertowctranstowlowertowupperungetcungetwcva_argva_copyva_endva_startvfprintfvfscanfvfwprintfvfwscanfvprintfvscanfvsprintfvsnprintfvsscanfvswprintfvswscanfvwprintfvwscanfwcrtombwcscatwcschrwcscmpwcscollwcscpywcscpywcsftimewcslenwcsncatwcsncmpwcsncpywcspbrkwcsptimewcsrchrwcsrtombswcsspnwcsstrwcstodwcstod32wcstod64wcstod128wcstofwcstokwcstolwcstoldwcstombswcstoulwcsxfrmwctobwctombwctranswctypewcwidthwmemchrwmemcmpwmemcpywmemmovewmemsetwprintfwscanfy0y1yn



Function Details : atol

longatol(const char * str) ;

Return Type : long

Large integer type (4 or 8 bytes platform dependent)
Read about return values of atol function .

1st Parameter Type : const char *

Pointer to read-only string

1st Parameter

Pointer to a null-terminated string representing a long integer value

Read more about parameters of atol in parameters section
The atolfunction in C language converts a string to a long integer.
The atol function converts the initial portion of the string pointed to by str to a long integer representation. It operates similarly to atoi, but returns a long int instead of an int. It skips any whitespace characters at the beginning of the string, then takes an optional plus or minus sign followed by as many base-10 digits as possible, and interprets them as a numerical value.
Important: atol function does not recognize decimal point as a decimal point and treats it just as another non-digit character which causes it to break the loop.

To Summarize the Workflow:
  1. 1.
    Takes a string (like "-123456789") as input.
  2. 2.
    Scans the string, ignoring leading whitespace.
  3. 3.
    If the string starts with a + or - sign, it interprets the number as positive or negative accordingly.
  4. 4.
    In case no sign found-sets result to positive as default
  5. 5.
    Then processes the character representations of digits (if present).
  6. 6.
    Stops at the first non-digit character (like a letter, symbol, or decimal point).
  7. 7.
    Does not recognize decimal points as part of the number.
  8. 8.
    Returns the long integer value of the processed digits (e.g., -123456789).
  9. 9.
    If the string doesn’t start with a valid number, it returns 0.


Read more about return type and value ofatol function in return section.
The atolfunction takes 1 parameter:
  • const char * `str`: Pointer to a null-terminated string representing a long integer value
Converts the initial portion of a string to a `long` value, interpreting the content as a decimal integer.
The atol function return value :
  • Returns the converted long integer value
  • If no valid conversion could be performed, it returns 0L

Output

This example demonstrates the basic usage of the `atol` function with different input strings, including a positive number, a negative number with leading whitespace, a very large number, and an invalid input.