#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

int main() {
    printf("practice1: 1st method of strtod\n");
    const char *str = "123.456xzy";
    char *endPtr;

    double numb = strtod(str, &endPtr);

    if(*endPtr == '\0')
        printf("the string \"%s\" converted to double: %f\n", str, numb);
    else
        printf("partial conversion: \"%s\" to \"%f\" stopped at \"%s\"\n", str, numb, endPtr);

    printf("practice2: 2nd method of strtod\n");
    double value = 0;
    char *input = "158.5 54.5 175.3 72.65";
    char *ptr = input;
    char *endP = NULL;

    while(true){
    value = strtod(ptr, &endP); //find not numb: from ptr to endP
    if(ptr == endP) //string comprise of only numb
    {
        break;
        printf("%f ", value);    
    } else
    {
    printf("%f ", value);
    ptr = endP;  
    }
   }


    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: