This blog is under construction

Monday, 30 April 2012

atof example in C

Header file:
    stdlib.h

Synopsis:
     double atof(const char *str);

Description:
     It converts string str to a double value.


atof function C example:


  #include<stdio.h>
  #include<stdlib.h>
  #include<string.h>
  int main() {
        char str[100];
        double val;
        printf("Enter your input:");
        fgets(str, 90, stdin);
        str[strlen(str) - 1] = '\0';
        val = atof(str);
        printf("Converted double value: %lf\n", val);
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Enter your input:123.455
  Converted double value: 123.455000




No comments:

Post a Comment