Is there any function of the type? Which reads and stores or returns a double of a string and returns or passes the rest of the string pointer or will I have to do my own function? If no one has ideas how to do this function optimally?
Is there any function of the type? Which reads and stores or returns a double of a string and returns or passes the rest of the string pointer or will I have to do my own function? If no one has ideas how to do this function optimally?
There is a function:
double strtod (const char* str, char** endptr);
It converts a number double
from the string passed as the first parameter, and plays a pointer to the rest of the string in the second parameter. Example:
#include <stdio.h>
#include <stdlib.h>
int main ()
{
char texto[] = "1.21 gigawatts";
char* resto;
double num;
num = strtod (texto, &resto);
printf ("Num: %f\n", num);
printf ("Resto: %s\n", resto);
return 0;
}
Output:
Num: 1.210000
Resto: gigawatts