#include <stdlib.h> double atof(const char *str) str : 変換される文字列
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *s;
double x;
int i;
long l;
s = "-2309.12e-15"; /* doubleへの変換 */
x = atof(s);
printf("文字列=%s 数値(double)=%e\n", s, x);
s = "6.775"; /* doubleへの変換 */
x = atof(s);
printf("文字列=%s 数値(double)=%f\n", s, x);
s = "-12345"; /* intへの変換 */
i = atoi(s);
printf("文字列=%s 数値(int)=%d\n", s, i);
s = "1234567890"; /* long intへの変換 */
l = atol(s);
printf("文字列=%s 数値(long)=%ld\n", s, l);
return 0;
}
文字列=-2309.12e-15 数値(double)=-2.309120e-12 文字列=6.775 数値(double)=6.775000 文字列=-12345 数値(int)=-12345 文字列=1234567890 数値(long)=1234567890
| 菅沼ホーム | 本文目次 | 演習問題解答例 | 付録目次 | 索引 |