Ver Mensaje Individual
  #17 (permalink)  
Antiguo 25/01/2012, 23:37
fightmx
 
Fecha de Ingreso: febrero-2003
Ubicación: D.F.
Mensajes: 163
Antigüedad: 21 años, 2 meses
Puntos: 22
Respuesta: Leer de Fichero

En este caso es conveniente utilizar strpbrk y strtod.
Código C:
Ver original
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main(){
  6.     char str[] = "sad12### -34.5666xxxx 99.01 asdasd7asd";
  7.     char key[] = "0123456789-+.";
  8.     double x;
  9.     char *pEnd = str;
  10.     char *pStart = strpbrk (pEnd, key);
  11.     while(pStart){
  12.         x = strtod(pStart, &pEnd);
  13.         if(pStart != pEnd)printf("%f\n", x);
  14.         else pEnd++;
  15.         pStart = strpbrk (pEnd, key);
  16.     }
  17.     return 0;
  18. }