Scroll Down to See All
abortabsacosasctimeasctime_rasinassertatanatan2atexitatofatoiatolbsearchbtowccalloccatclosecatgetscatopenceilclearerrclockcoscoshctimectime_rdifftimediverferfcexitexpfabsfclosefdopenfeofferrorfflushfgetcfgetposfgetsfgetwcfgetwsfopenfprintffputcfputwsfreadfreefreopenfrexpfscanffseekfsetposftellfwidefwprintffwritefwscanfgetcgetchargetenvgetwcgetwchargmtimegmtime_rhypotisalnumisalphaisasciiisblankiscntrlisdigitisgraphislowerisprintispunctisspaceisupperiswalnumiswalphaiswblankiswcntrliswctypeiswdigitiswgraphiswloweriswprintiswpunctiswspaceiswupperiswxdigitisxdigitj0j1jnlabsldexpldivlocaleconvlocaltimelocaltime_rloglog10longjmpmallocmblenmbrlenmbrtowcmbsinitmbsrtowcsmbstowcsmbtowcmemchrmemcmpmemcpymemmovememsetmktimemodfnextafternextafterlnexttowardnexttowardlnl_langinfoperrorpowprintfputcputcharputenvputsputwcputwcharqsortquantexpd32quantexpd64quantexpd128quantized32quantized64quantized128samequantumd32raiserandrand_rreallocregcompregerrorregexecregfreeremoverenamerewindscanfsetbufsetjmpsetlocalesetvbufsignalsinsinhsnprintfsprintfsqrtsrandsscanfstrcasecmpstrcatstrchrstrcmpstrcollstrcpystrcspnstrerrorstrfmonstrftimestrlenstrncasecmpstrncatstrncmpstrncpystrpbrkstrptimestrrchrstrspnstrstrstrtodstrtod32strtod64strtod128strtokstrtok_rstrtolstrtoldstrtoulstrxfrmswprintfswscanfsystemtantanhtimetime64tmpfiletmpnamtoasciitolowertouppertowctranstowlowertowupperungetcungetwcva_argva_copyva_endva_startvfprintfvfscanfvfwprintfvfwscanfvprintfvscanfvsprintfvsnprintfvsscanfvswprintfvswscanfvwprintfvwscanfwcrtombwcscatwcschrwcscmpwcscollwcscpywcscpywcsftimewcslenwcsncatwcsncmpwcsncpywcspbrkwcsptimewcsrchrwcsrtombswcsspnwcsstrwcstodwcstod32wcstod64wcstod128wcstofwcstokwcstolwcstoldwcstombswcstoulwcsxfrmwctobwctombwctranswctypewcwidthwmemchrwmemcmpwmemcpywmemmovewmemsetwprintfwscanfy0y1yn



Function Details : strtof

floatstrtof(const char * nptr,char ** endptr) ;

Return Type : float

Single-precision floating point (±3.4E±38, ~7 decimal digits)
Read about return values of strtof function .

1st Parameter Type : const char *

Pointer to read-only string

1st Parameter

Pointer to the null-terminated string that represents the number to be converted.

2nd Parameter Type : char **

A pointer to a pointer to a null-terminated string. Commonly used in functions like `strtol` and `strtok_r` to store the address of the first invalid character or to maintain state across function calls.

2nd Parameter

Pointer to a character pointer that will store the address of the first invalid character after the number in `nptr`.

Read more about parameters of strtof in parameters section
The strtoffunction in C language Converts the initial portion of the string to a floating-point number.
The strtof function converts the initial portion of the string pointed to by nptr to a float. It skips leading whitespace, converts the subsequent characters as part of the number, and stops at the first character it cannot recognize as part of a number. If endptr is not NULL, it stores the address of the first invalid character in *endptr.
The strtoffunction takes 2 parameters:
  • const char * `nptr`: Pointer to the null-terminated string that represents the number to be converted.
  • char ** `endptr`: Pointer to a character pointer that will store the address of the first invalid character after the number in `nptr`.
Converts the initial portion of the string pointed to by `nptr` to a `float`. The conversion stops at the first invalid character. If `endptr` is not NULL, it points to the character after the last valid character used in the conversion.
The strtof function return value :
  • Returns the converted float value
  • If no conversion could be performed, 0
  • 0f is returned
  • If the correct value is outside the range of representable values, HUGE_VALF (with the correct sign) is returned and errno is set to ERANGE

Output

This example demonstrates basic usage of strtof to convert a string to a float and identify the remainder of the string.