27.6k views
5 votes
Which C99 function can be used to convert a string to a double?

User Vonda
by
5.5k points

1 Answer

3 votes

Answer:

atof

Step-by-step explanation:

atof function is used to convert a string to a double.

It takes a single parameter of type const char * and returns a double value.

The function signature is: double atof (const char* str);

In order to use this function in the code, you need to include the header file <stdlib.h>

For example:

#include <stdio.h>

#include <stdlib.h>

int main()

{

char str[5] = "0.01";

double d = atof(str);

printf("Value = %f\\", d);

return 0;

}

User Arthur Chaparyan
by
6.2k points