jweinst1
10/5/2017 - 4:41 PM

example of using strtod in c

example of using strtod in c

/* strtod example */
#include <stdio.h>      /* printf, NULL */
#include <stdlib.h>     /* strtod */

int main ()
{
  char szOrbits[] = "365.24 29.53";
  char* pEnd;
  double d1, d2;
  d1 = strtod (szOrbits, &pEnd);
  d2 = strtod (pEnd, &pEnd);
  printf ("The moon completes %.2f orbits per Earth year.\n", d1/d2);
  pEnd--;
  printf("Last points to %c", *pEnd);
  return 0;
}