Ver Mensaje Individual
  #18 (permalink)  
Antiguo 26/01/2012, 05:17
johncapi
 
Fecha de Ingreso: enero-2012
Mensajes: 32
Antigüedad: 12 años, 3 meses
Puntos: 1
Respuesta: Leer de Fichero

Cita:
Iniciado por fightmx Ver Mensaje
En este caso es conveniente utilizar [URL="http://www.cplusplus.com/reference/clibrary/cstring/strpbrk/"]strpbrk[/URL] y [URL="http://www.cplusplus.com/reference/clibrary/cstdlib/strtod/"]strtod[/URL].
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. }
Estas 2 funciones no las conocia !!!! Han sido de gran utilidad !!!!
Ahora si solo quiero introducir ese double (x) en un vector (vec) solamente tengo que hacer una asignacion ?!?!?
Código:
while(pStart){
        x = strtod(pStart, &pEnd);
        vec[i] = x;
        i++;
        if(pStart != pEnd)printf("%f\n", x);
        else pEnd++;