1. Atof (convert string to floating-point number)
Related functions
Atoi,atol,strtod,strtol,strtoul
Table header File
#include <stdlib.h>
Defining functions
Double atof (const char *nptr);
Function description
Atof () scans the parameter nptr string and skips the preceding space character until it encounters a number or sign to begin the conversion, and then ends the conversion without a number or at the end of the string, returning the result. The parameter nptr string can contain a positive sign, a decimal point, or E (e) to represent the exponent portion, such as 123.456 or 123e-2.
return value
Returns the number of floating-point types after conversion.
Additional Instructions
Atof () is the same as the result of using Strtod (nptr, (char**) NULL).
Example
/* Convert string A and string B to number after adding/*
#include <stdio.h>
#include <stdlib.h>
main ()
{
char *a= " -100.23";
Char *b= "200e-2";
float C;
C=atof (a) +atof (b);
printf ("c=%.2f\n", c);
}
2.atoi (convert string to Integer)
Related functions:
Atof,atol,atrtod,strtol,strtoul
Table header file:
#include <stdlib.h>
To define a function:
int atoi (const char *nptr);
Function Description:
Atoi () scans the parameter nptr string and skips the preceding space character until it encounters a number or sign to begin the conversion, and then ends the conversion without a number or at the end of the string, returning the result.
return value:
Returns the converted integer number.
Additional Instructions:
Atoi () with the use of Strtol (nptr, (char**) null,10);
Example:
/* Convert string A and string B to number after adding/*
#include <stdio.h>
#include <stdlib.h>
main ()
{
char a[]= ";
" Char b[]= "256";
int C;
C=atoi (a) +atoi (b);
printf ("c=%d\n", c);
}