/* Collection of code snippets by Arne Vajhøj */
/* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) */
#include <stdlib.h>
#include <stdio.h>

void testi(char *s)
{
   int v;
   char *ep;
   v = atoi(s);
   printf("%s = %d\n",s,v);
   v = strtol(s, &ep, 10);
   if(ep > s)
   {
      printf("%s = %d\n",s,v);
   }
   else
   {
      printf("%s not number\n",s);
   }
}

void testfp(char *s)
{
   double v;
   char *ep;
   v = atof(s);
   printf("%s = %f\n",s,v);
   v = strtod(s, &ep);
   if(ep > s)
   {
      printf("%s = %f\n",s,v);
   }
   else
   {
      printf("%s not number\n",s);
   }
}

int main()
{
   testi("123");
   testi("abc");
   testfp("123.456");
   testfp("abc.def");
}
