c언어 char 배열를 실수로 변환하는거 질문드려요
조회수 1943회
-
(•́ ✖ •̀)
알 수 없는 사용자
1 답변
-
다음 두 함수를 참고해보세요.
// stod example #include <iostream> // std::cout #include <string> // std::string, std::stod int main () { std::string orbits ("365.24 29.53"); std::string::size_type sz; // alias of size_t double earth = std::stod (orbits,&sz); double moon = std::stod (orbits.substr(sz)); std::cout << "The moon completes " << (earth/moon) << " orbits per Earth year.\n"; return 0;
/* atof example: sine calculator */ #include <stdio.h> /* printf, fgets */ #include <stdlib.h> /* atof */ #include <math.h> /* sin */ int main () { 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; }
댓글 입력