- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
strtod() function in C/C++
The function strtod() is used to convert the string to a floating point number. The string is converted into double type number. It returns the converted number, if successful otherwise, zero. This is declared in “stdlib.h” header file.
Here is the syntax of strtod() in C language,
double strtod(const char *string, char **endpointer);
Here,
string − The string to be converted.
endpointer − The pointer of already allocated object and its value is set to the next character by the function after the numeric value.
Here is an example of strtod() in C language,
Example
#include <stdio.h> #include <stdlib.h> int main () { char s[20] = "8.28 is a number"; char *p; double result; result = strtod(s, &p); printf("The number after conversion of string : %lf", result); return(0); }
Output
The number after conversion of string : 8.280000
In the above program, a char type array s[20] is declared which is initialized with a alphanumeric characters. The function strtod() is used to convert that string into a double number.
char s[20] = "8.28 is a number"; char *p; double result; result = strtod(s, &p);
Advertisements