/ * atof function: the string s into the corresponding double precision floating point * /
#include <ctype.h>
Double the atof (char s [])
{
Double Val, Power;
int I, Sign;
for (I = 0 ; isspace (s [i]) ; i ++) / * isspace determines whether whitespace * /
;
Sign = (S [I] == '-') -1:?. 1;
iF (S [I] == ' + '|| S [I] ==' - ')
I ++;
for (Val = 0.0; isdigit (S [I]); I ++) / * isdigit determines whether the digital * /
Val = 10.0 * Val + (S [I ] - '0');
IF (S [I] ==) '.'
I ++;
for (Power = 1.0; isdigit (S [I]); I ++)
{
Val = 10.0 * Val + (S [I] - ' 0 ');
Power = 10.0 *;
}
return * Sign Val / Power;
}
#include <ctype.h>
Double the atof (char s [])
{
Double Val, Power;
int I, Sign;
for (I = 0 ; isspace (s [i]) ; i ++) / * isspace determines whether whitespace * /
;
Sign = (S [I] == '-') -1:?. 1;
iF (S [I] == ' + '|| S [I] ==' - ')
I ++;
for (Val = 0.0; isdigit (S [I]); I ++) / * isdigit determines whether the digital * /
Val = 10.0 * Val + (S [I ] - '0');
IF (S [I] ==) '.'
I ++;
for (Power = 1.0; isdigit (S [I]); I ++)
{
Val = 10.0 * Val + (S [I] - ' 0 ');
Power = 10.0 *;
}
return * Sign Val / Power;
}
/ * The following example is a simple calculator program, the program reads in each line a number
(the number may have a front sign), and summing them, after each completion of the input
of these numbers print out cumulative sum * /
#include <stdio.h>
#define MAXLINE 100
main ()
{
Double sUM, the atof (char []);
char Line [MAXLINE];
int getline (Line char [], int max); / * here getline function, supra few * /
SUM = 0; / * getline row stored in the line, and returns the length of the line * /
the while (getline (line MXLINE)> 0)
the printf ( "\ T% G \ n-", the atof = SUM + (Line));
return 0;
}
(the number may have a front sign), and summing them, after each completion of the input
of these numbers print out cumulative sum * /
#include <stdio.h>
#define MAXLINE 100
main ()
{
Double sUM, the atof (char []);
char Line [MAXLINE];
int getline (Line char [], int max); / * here getline function, supra few * /
SUM = 0; / * getline row stored in the line, and returns the length of the line * /
the while (getline (line MXLINE)> 0)
the printf ( "\ T% G \ n-", the atof = SUM + (Line));
return 0;
}