How to extract double and substring from a string in C

1 Answer

0 votes
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    char* str = "965.847209 C Programming";
    char* endptr;

    // double strtod(const char *str, char **endptr)
    
    double dbl = strtod(str, &endptr);

    printf("double: %lf\n", dbl);
    printf("string: %s", endptr);
       
    return 0;
}
    
     
     
     
/*
run:
  
double: 965.847209
string:  C Programming
 
*/

 



answered Nov 16, 2023 by avibootz
...