atof - C stdlib.h

C examples for stdlib.h:atof

Type

function

From


<cstdlib>
<stdlib.h>

Description

Convert string to double

Prototype

double atof (const char* str);

Parameters

Parameter Description
str C-string representation of a floating-point number.

Return Value

On success, the function returns the converted floating point number.

On error, the function returns zero (0.0).

Demo Code


#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main ()/*from  w ww.  j av a  2 s . com*/
{
  double n,m;
  double pi=3.1415926535;

  char buffer[256];

  printf ("Enter degrees: ");

  fgets (buffer,256,stdin);

  n = atof (buffer);

  m = sin (n*pi/180);

  printf ("The sine of %f degrees is %f\n" , n, m);

  return 0;
}

Related Tutorials