학습 내용 : 소수점이 포함된 문자열을 실수값으로 변환하는 방법을 이해합니다.

 

소스 코드 :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <stdio.h>
#include <stdlib.h>
 
void main()
{
    char *string1 = "3.141592... 원주율";
    char *string2 = "원주율 3.141592...";
    float tempFloat1 = -1;
    float tempFloat2 = -1;
 
    puts(string1);
    puts(string2);
 
    tempFloat1 = atof(string1);
    tempFloat2 = atof(string2);
 
    printf("%f\n", tempFloat1);
    printf("%f\n", tempFloat2);
}
 

 

 

실행 화면 :