Saber si argv es un numero real

Iniciado por javituni, 6 Noviembre 2013, 17:14 PM

0 Miembros y 1 Visitante están viendo este tema.

javituni

Hola buenas, he buscado en google y no consigo averiguar como saber si un parámetro argv es un numero real. Encontre la función isdigit pero al hacer isdigit(argv) me da error porque no puedo pasarle un puntero. Alguna idea? Gracias. 

javituni


rir3760

Hay varias formas de realizar la operación, para ello puedes utilizar las funciones atof, strtod o sscanf. El uso de esta ultima seria mas o menos así:
char ejemplo[] = "algun texto";
double numero;

/* ... */

if (sscanf(ejemplo, "%lf", &numero) == 1){
   printf("Es un numero (%f)\n", numero);
}


Un saludo
C retains the basic philosophy that programmers know what they are doing; it only requires that they state their intentions explicitly.
--
Kernighan & Ritchie, The C programming language

javituni